[SDL] Loading bitmaps with transparency?

Ryan C. Gordon icculus at icculus.org
Sun Mar 4 03:45:02 PST 2007


> I can't use any of the C++ libraries 'cause I'm on Lua.
> 
> Maybe transparency masks, where there's a separate black-and-white 
> bitmap with the black areas as the background and white areas as what I 
> want to show? Would that be best or no?

(You found you've got alpha channels in PNG files in the Lua 
distribution, but for the record here...) what you're describing is 
called a "Color Key" ... pick some color in the bitmap you don't need 
(like, bright purple) and tell SDL that whenever it sees that color, 
don't draw the pixel...if all you want to do is mask out pixels so your 
sprite isn't a rectangle (and is instead shaped like, say, Mario), 
that's what you want, since it's faster than using an alpha channel.

If you want to have some pixels blend with whatever's behind it instead 
of overwriting it (like, the slightly-tinted window in a door sprite), 
you need the alpha channel.

If you just want the whole sprite to blend with the background (like 
something fading in or out completely), you can use "per-surface alpha".

Only the second option would need a .png ... the rest are faster and can 
be done with SDL directly by passing it simple integer values and not 
byte arrays, and thus should be usable from Lua.

--ryan.



More information about the SDL mailing list