• Advertisement
Sign in to follow this  

SDL Alpha blending and transparency

This topic is 4793 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, im trying to get sprites to be transparent. Currently im loading in the PNG image using SDL_image library, and it creates a sprite with transparency wherever there is a bright green color, which i specified. what i want to do now with that sprite is make it so it alpha blends with the background. Does anyone have any code that can help me with this??

Share this post


Link to post
Share on other sites
Advertisement
you can use per-surface alpha blitting were the entire image will be made translucent this should tell you what you need to know http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fSetAlpha

if not let me know

hope i helped [smile]

Share this post


Link to post
Share on other sites
From what I have read in the SDL docs the following is a brief explaination of using alpha channels and colorkeys:

You can use a surface colorkey OR per pixel alpha.
You can use a surface colorkey AND per surface alpha.

Share this post


Link to post
Share on other sites
I use color keying and alpha-blending on some of my surfaces. First set the color key. Then, to set the alpha you would:
// assuming 's' is an SDL_Surface* and 'alpha_val' is and int between 0 and 255 with 255 being opaque and 0 being transparent
SDL_SetAlpha( s, SDL_SRCALPHA, alpha_val );

Share this post


Link to post
Share on other sites
Quote:
Original post by PnP Bios
Use OpenGL.

Sometimes SDL can be faster, PnP. Like, I'm working on a little game that detects if the user has OpenGL drivers, but if they don't, then it falls back on SDL. Why would I do this, well OpenGL is incredibly slow if you don't have a card that supports it, and one of the people who were testing my game said they got like 3-4 fps with OpenGL mode but 50-60 fps with SDL. Why? They had a Radeon7000, which only has support for DX7 and below. They bought their computer in 2002. With a 2.2 Ghz processor, it was able to get better fps with SDL rendering than with OpenGL doing the rendering.

But nice library you're making, and in most cases these days, OpenGL is faster, especially because my laptop with an Intel Integrated Graphics card has OpenGL drivers, and I get like 10x the fps using OpenGL than I did with SDL. I can only imagine fps what people with actual graphics cards would get.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement