Skip to main content
gamedev.net
🔒 Locked

Transparency ?

Started by mtd Aug 8, 2005 at 9:03 PM 1 replies 650+ views
Original Post
mtd
mtd
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
TomasH
TomasH
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.
el capitan
el capitan
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.