Advertisement

SDL Alpha blending and transparency

Started by January 06, 2005 08:30 PM
4 comments, last by wyrzy 20 years, 1 month ago
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??
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]
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Advertisement
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.
Evillive2
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 );
Use OpenGL.
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
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.

This topic is closed to new replies.

Advertisement