Alpha-masking In Sdl


timbobsteve

Member
Joined
Oct 4, 2005
Messages
301
Hi All,

I have a question regarding translucency in sprites usins SDL. Is it possible? I have worked with ColorKey's in SDL to create transparent sections on a Bitmap/Sprite/Surface etc, but never say 50% Transparency. Has anyone got any info or links to tutorials?

Thanks again.
 
You can use the SDL_SetAlpha function to set an alpha value for an entire surface. I'm actually just about to try this out and see what kind of speeds I get with it, I think I might have to implement my own addition transparency to get it to work fast enough. We'll see...
 
OK, SDL_SetAlpha is really, really slow... just for fading a simple 4-color bitmap in and out it went at between 1/4 and 1/8 speed.

I think I'll write something to do an "approximate" fade that doesn't hit every alpha level, only ones that I can optimize using bit shifts instead of divides. Umm, I'll see how that turns out I guess...

OK, this is kind of weird. If you request a 32-bit SW_SURFACE, even though you can't use 32-bit graphics, it's a lot faster than requesting 16-bit (and I can't get 8-bit to work for this). It seems to run at about 1/2 speed.
 
Mudi posted on Feb 27 2006 at 02:39 AM said:
OK, this is kind of weird. If you request a 32-bit SW_SURFACE, even though you can't use 32-bit graphics, it's a lot faster than requesting 16-bit (and I can't get 8-bit to work for this). It seems to run at about 1/2 speed.
The SDL_gfx alpha functions always copy a 16 bit surface to a 32 bit one before performing the function, then they copy it back to a 16 bit surface again. Starting with a 32 bit surface speeds those functions up a bit. I don't know if SDL_SetAlpha works in the same way, but it certainly sounds like it might do.
 
Last edited by a moderator:
Back
Top