[SDL] Fade question

Bob Pendleton bob at PENDLETON.COM
Tue Jun 25 07:40:01 PDT 2002


In 8 bit mode the easiest way to do it is to write the color palette in 
a loop. Each time you write the palette modify the color values so they 
are closer and closer to black. Use a timer to control the time used for 
the fade. This will do a true fade to black. You do have to be careful 
with the arithmetic on the palette items to avoid negative values and to 
make sure that all the colors reach black at the same time, else you get 
a weird ghosting effect as the bright colors fade out after the dark 
colors. Of course, you might like that effect.

The result is the screen is black and all the palette entries are 
0x000000. This lets you paint what ever you want on the screen and then 
when you load a palette with your colors they appear on the screen 
instantly. We used this technique a lot in the old DOS/VGA days.

Another way to do it is to write black over the buffer starting at the 
first pixel and picking the next pixel using something like:
(pixel + 7) mod buffer_size
(But, obviously not exactly like that.) So that after you have reached 
the end of the buffer 7 times the whole buffer is black. The effect is 
rather nice if done quickly enough. You want to pick a number that is 
relatively prime to the width of the buffer so that you don't get 
vertical stripes, but rather a psuedo random pattern of pixels that is 
guarantedd to cover the entire buffer.

		Bob Pendleton


Jason Brunson wrote:
> I am new to game programming and graphics programming.  I have a 
> question regarding fading in and out of a screen.  I have looked 
> throught the archives and done a site search to find some info on gamma 
> fading.  However, I cannot get it to work for me.  I am in 8bit mode and 
> am wanting to fade out to black.  Using SDL_SetGamma does not seem to 
> work.  Any clues?
> Thanks, Jason


-- 
+------------------------------------------+
+ Bob Pendleton, an experienced C/C++/Java +
+ UNIX/Linux programmer, researcher, and   +
+ system architect, is seeking full time,  +
+ consulting, or contract employment.      +
+ Resume: http://www.jump.net/~bobp        +
+ Email:  bob at pendleton.com                +
+------------------------------------------+





More information about the SDL mailing list