[SDL] SDL_SetColorKey problem
Alex Volkov
avcp-sdlmail at usa.net
Mon Jan 9 09:22:31 PST 2006
Jorge Navarro wrote:
> Im trying to use the SDL_SetColorKey function, but sprites are
> drawn with green color.
...
> if (SDL_SetColorKey(temp, (SDL_SRCCOLORKEY | SDL_RLEACCEL),
SDL_MapRGB(temp->format, 0x00,0xFF,0x00 )) < 0)
...
> *pointer_fichbmp = SDL_ConvertSurface(temp, gScreen->format,
SDL_SWSURFACE);
You are removing the the colorkey with that last call. Try something like:
*pointer_fichbmp = SDL_ConvertSurface(temp, gScreen->format,
temp->flags | SDL_SWSURFACE);
Also, keep in mind that depending on exact surface formats involved and on
which blitter is chosen to do the conversion from your loaded format to the
gScreen format, the full-green pixels (00,ff,00) may get changed to non-full
(for example, (00,f8,00)) and the colorkey may undergo a slightly different
conversion, which will make it desynchronized with the transparent surface
pixels. Since you are already hard-coding transparent green here, it may be
a better choice for you to read an already converted pixel from a
pre-defined location in the image (i.e. from x=0, y=0) and use that pixel as
the colorkey for the converted surface.
With images loaded from files, alpha channel transparency is often a better
choice. Alternatively, colorkeys work very well with indexed (8bpp paletted)
images, and you would not need to convert indexed images to a target format
beforehand -- just blit them to the screen (?) when you need to.
-Alex.
More information about the SDL
mailing list