[SDL] HOWTO color cycling

Lutz Sammer johns98 at gmx.net
Mon Aug 27 08:37:01 PDT 2001

Jo wrote:
> Hi fellow,
>    Some time ago, someone (David Olafson, I think) asked for doing color
> cycling when you can't really use hardware palette.
>    Color cycling is an old *trick* to make movement effect only by doing a
> palette rotation that cost nothing compared to sprite movement. Tou can see
> this effect, for exemple, in animated fountains or waterfalls (like in
> Sonic). It was still in use in DOS VGA 256-color games, so it's required
> when porting old games to SDL.
>    The problem is that in 15-or-more bits modes, there is no more hardware
> palette; the pixels store their RGB(+alpha) into themselves. To do an
> equivalent effect, you need to reserve a range of colors (to keep cycling
> pixel position) and to replace on-the-fly theses pixels by the good color
> values. It's CPU intensive, and unhandy.
>    The way I found to achieve this effect is the following one.
>    If you want to do color cycling on sprites/pictures, you should have
> these pictures in 8 bits format. To load them fine in SDL, you need to load
> their palettes as well (in my_surface->format->palette). Alright ? Don't you
> see where I am going ? Yes: just do the palette rotation into the pictures'
> palettes. So when you blit them on your screen, SDL will use the newly
> changed palettes. Not so diffucult, you see !
>    The only counterpart of this method is that you mustn't convert the
> pictures' display format to the screen' (this is a well known way to improve
> blitting speed). Otherwise you could lost your palettes, and prevent color
> cycling.
>    Am I wrong ? If yes, please correct this stuff.

Everything is right, but palette images are faster, if working in
system memory or blitting from system memory to video memory. 
Only if the blitting is hardware accelerated or you are blitting
from hardware to hardware memory the palette images could be slower.

Become famous, earn no money, create music or graphics for FreeCraft
http://FreeCraft.Org        - A free real-time strategy game engine
http://FreeCraft.Net/fcgp   - The FreeCraft Graphics Project
http://FreeCraft.Net/fcsp   - The FreeCraft Sound Project

More information about the SDL mailing list