[SDL] colour cycling

David Olofson david.olofson at reologica.se
Tue Oct 9 16:42:01 PDT 2001


On Wednesday 10 October 2001 01:26, Darrell Walisser wrote:
> On Tuesday, October 9, 2001, at 03:32 PM, James wrote:
> > Is there an easy way to do that vomit-inducing colour cycling you see
> > in old games and fractal generators?
>
> Yes.
>
> > I've created an 8bit 640x480 palletised surface, and have drawn some
> > things on it.
> >
> > The kind of cycling I'd like is the one where each colour in the
> > palette is shoved one space forwards. I tried doing this with
> > SDL_SetPalette(), but couldn't work out how to get the palette for a
> > surface.
> >
> > I managed to rotate an empty SDL_Color array's elements, but of
> > course an empty SDL_Color array has a palette with all colours set to
> > black, which doesn't look very good when cycled :-)
> >
> > so if I have an SDL_Surface 'screen', how do I get the palette for
> > this as an SDL_Color array? (or is there a better way?).
>
> First, make sure you use SDL_HWPALETTE as a flag passed to
> SetVideoMode().
> Then, read the screen's palette from screen->format->palette, writing
> the new values to your array of SDL_Color. Then use SDL_SetColors() to
> set the new palette.
>
> Easy, right?

And, if it for some reason is impossible to get an 8 bit mode, it may be 
possible to "abuse" the gamma correction tables to simulate it in 24 or 
32 bit modes. In short, render everything as grayscales, and then 
translate the scale into a 256 color palette, that you load into the 
gamma tables. You may then play with the gamma tables as you like, as if 
they were a "real" h/w palette.


//David Olofson --- Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
|      Multimedia Application Integration Architecture      |
| A Free/Open Source Plugin API for Professional Multimedia |
`----------------------------> http://www.linuxdj.com/maia -'
.- David Olofson -------------------------------------------.
| Audio Hacker - Open Source Advocate - Singer - Songwriter |
`-------------------------------------> http://olofson.net -'




More information about the SDL mailing list