Xref: news2.mv.net comp.os.msdos.djgpp:2969 From: jasonk AT direct DOT ca (Jason Keddie) Newsgroups: comp.os.msdos.djgpp Subject: Re: Allegro + pallete fades Date: Tue, 23 Apr 1996 00:24:58 GMT Organization: Keddie Enterprises Lines: 71 Message-ID: <4lh7is$t62@orb.direct.ca> References: <317561DD DOT A86 AT gl DOT umbc DOT edu> <4la5q0$6rg AT news DOT wco DOT com> Reply-To: jasonk AT direct DOT ca NNTP-Posting-Host: vic-as-01a13.direct.ca To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp This is my function for fading out the color palette. I don't claim that it's great or anything but it works so maybe it will help. I like to use the fractional approach because if you just subtract one from r/g/b dark screens will fade out too fast. You could pass it a number to use instead of 18643 if you want to be able to control the speed of the fade. /*This is what colorType is*/ struct colorType { unsigned char r:6; unsigned char g:6; unsigned char b:6; }; void fadePaletteOut(void) { colorType savedPalette[256]; unsigned long index, lastTime, intensityIndex; /*Save the palette*/ for(index=0;index<256;index++) { outportb(0x3c7,index); savedPalette[index].r = inportb(0x3c9); savedPalette[index].g = inportb(0x3c9); savedPalette[index].b = inportb(0x3c9); } /*slowly lower palette to black*/ lastTime = clock(); for(intensityIndex=64;intensityIndex>0;intensityIndex--) { do{}while ((lastTime + 18643) > uclock()); lastTime = uclock(); for(index=0;index<256;index++) { outportb(0x3c6,0xff); outportb(0x3c8,index); outportb(0x3c9,((savedPalette[index].r << 4) * intensityIndex)>>10); outportb(0x3c9,((savedPalette[index].g << 4) * intensityIndex)>>10); outportb(0x3c9,((savedPalette[index].b << 4) * intensityIndex)>>10); } } /*clear screen and reload saved palette*/ clearVideoBuffer(); writeVideoBuffer(); for(index=0;index<256;index++) { outportb(0x3c6,0xff); outportb(0x3c8,index); outportb(0x3c9,savedPalette[index].r); outportb(0x3c9,savedPalette[index].g); outportb(0x3c9,savedPalette[index].b); } } jasonk AT tnet DOT net