‘flag’ is an integer where each bit has a special meaning. There are
defines in the SDL headers that assign sensible names to bits and
patterns of bits - you should alwmays use these and not worry about
which actual bits you’re dealing with.
In your case, you should pass ‘SDL_SRCCOLORKEY’ for the ‘flag’ argument.
For performance in software rendering, you could also add ‘SDL_RLEACCEL’,
which encodes the surface in a way that allows a faster software blitter
to be used. To combine flag defines, use the ‘|’ (logic OR) operator:
‘SDL_SCRCOLORKEY | SDL_RLEACCEL’.
‘key’ is the pixel value of the color you want to be transparent. Note
that it’s NOT an 8:8:8 RGB value, unless your surface happens to be in
that format! You should construct this value using SDL_MapRGB(), passing
the pixel format struct from your surface as the ‘fmt’ argument, and your
RGB color as the r, g and b args. (range: 0…255.)
In short:
SDL_SetColorKey(your_surface, SDL_SRCCOLORKEY | SDL_RLEACCEL,
SDL_MapRGB(your_surface->format, 255,255,255));
Do note that the “white” color of your image must have exactly the
value of 255,255,255 (0xffffff), or the image will remain opaque!
(I’ve noticed that both GIMP and PhotoShop have rounding errors in the
indexed<->RGB conversion code, so 255 becomes 254 if you convert back and
forth.)
//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 |
--------------------------------------> david at linuxdj.com -'On Thursday 13 September 2001 19:15, Pedro Santos wrote:
hi,
I have this problem, I have an image with jsut 2 colors,
black as white, and I want to make all the white
transparent.
int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key);
should do, but I don’t know how to work with this, because
de concepts of flag and key are strange to me ( newbie writing ).