[SDL] Transparency

Stefan Viljoen rylan at intekom.co.za
Mon Nov 10 11:32:00 PST 2003

From: Stephane Marchesin <stephane.marchesin at wanadoo.fr>

Stefan Viljoen wrote:

>Hi all,

>Given this code:

I don't know what that line does, but it's definitely wrong.
See the SDL_SetAlpha manpage for more info :

Thanks Stephane               

>>                         SDL_MapRGB(buttons[OK_BUT_PRESSED]->format,0,0,0));



>>//End code

>>Can anybody tell me WHY black pixels still do not get masked out? Both 

>>and buttons[OK_BUT_PRESSED] is loaded from a .JPEG file, which has its 
>>transparent areas set to RGB8 0,0,0 using the GIMP.

>It might also happen that the jpeg compression loses "perfectly black" 
>pixels in favor of "almost black" pixels. Usually you can't see the 
>difference, but SDL will.

Darn - what file format can I use to store graphics, except JPG, that will not 
"lose" certain colors? JPEG compresses nicely, but if it does this it 
obviously cannot be used for sprites. TGA? BMP? What would be best?
I think you might have hit it on the nose here. Anybody else got any ideas?

>>Any ideas anyone? Pointers to where I can get example code showing how to 
>>implement totally transparent pixels in a source surface?

>It depends on what you want. Do you want both translucency and 
>colorkeying ? Looking at your message, it seems not. So you shouldn't 
>use both SDL_SetAlpha and SDL_SetColorKey at the same time. Try removing 
>the SDL_SetAlpha call.

Hmm - did remove the setalpha call - still does not take the "black" pixels 
out. On the first question, no I do not want translucency - just transparency 
in certain areas with "black" pixels.

Anyway, thanks Stephane! 

I appreciate it


Stefan Viljoen
F/EMS Dispatcher
Potchefstroom Public Safety Dept.
Republic of South Africa

"We want you to be soldiers - deadly as long as you have one leg or one arm 
and you are still alive."
 - R. A. H. in Starship Troopers

More information about the SDL mailing list