Mail Archives: djgpp/1996/04/22/21:50:09
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
- Raw text -