Advertisement Jump to content
Sign in to follow this  
mtd

OpenGL Transparency ?

This topic is 4914 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

I'm doing a 2D over the top view game with SDL & OpenGL Basically, I draw out the ground first, then draw the hero over top, all using texture-mapped openGL squares. On the sprite, I have set the background of the bmp to (255,0,255) so that I can make it transparent. How can I make it so that only the non (255,0,255) coloured part of the sprite is opeque while the rest is transparant so that I can see the ground through him? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Start by adding an alpha channel to your image, either in Photoshop or Gimp or whatever you use, or by doing it in the program when you load the image. Set the alpha channel, so that the opaque pixels have alpha 255 and that the transparent ones have alpha zero.
In your program do:
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER,0.5);

Now only the pixels (or texels, actually) with alpha>0.5 (alpha 255 equals 1.0 on this scale) will be drawn.

Share this post


Link to post
Share on other sites
Or get a key color to the transparent section, then take the color value of the key color and decalre it transparent while creating the texture.

Something like this:

if(r == 1 && g == 21 && b == 3)
a = 0;
else
a = 255;




This as is does not handle smooth blending through alpha but it handles well hard transparency.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!