[SDL] Alpha blending transparent PNGs

David Olofson david at olofson.net
Sat Oct 20 12:47:16 PDT 2007


On Saturday 20 October 2007, Cracker wrote:
[...]
> David Olofson wrote:
[...]
> "Yes, you can use colorkeying together with full surface alpha."
> And is it possible without colorkey-ing? I don't want to set a
> colorkey color, I just want to use the alpha as the background.

Not directly, AFAIK. You'd have to decide on a key color in the code 
and then scan the surface, writing that color to pixels that are 
supposed to be transparent, so you can use SDL colorkeying.

BTW, an easy way of doing this kind of (pre-)processing is to 
SDL_ConvertSurface() surfaces into a specific 32 bit RGBA format, do 
your processing, and then SDL_DisplayFormat() or 
SDL_DisplayFormatAlpha() when done. This way, you don't have to worry 
about pixel formats, so you only need one implementation of each 
processing filter. SDL conversions are pretty fast, so the extra 
conversions are no big deal, at least not for load/init time 
processing.


//David Olofson - Programmer, Composer, Open Source Advocate

.-------  http://olofson.net - Games, SDL examples  -------.
|        http://zeespace.net - 2.5D rendering engine       |
|       http://audiality.org - Music/audio engine          |
|     http://eel.olofson.net - Real time scripting         |
'--  http://www.reologica.se - Rheology instrumentation  --'


More information about the SDL mailing list