Sign in to follow this  
SomeoneX

openGL transparency

Recommended Posts

I was looking for information on how to load a texture with a transparent color, something like SDL's color keying or alpha. I saw some code that actually accomplished this, but did not see any explanations for how or why it does so. The code I looked at was in the NeHe tutorials (lesson 9). Fairly new to openGL, but I think I understand the basics enough to try and throw a little project together, except for this little stumbling block.

Share this post


Link to post
Share on other sites
Basically, what you do is the following:

You load the image (texture). Let's say you colorkey off the first pixel in the image, but this can apply to any color. So, getColor(0,0) ... pseudo code for get the color in the upper left corner of the image; this will be the transparent color. You will have a color with red, green, blue, and alpha values. Then you replace all instances of this color in the image with a color with the same r, g, b values, but you make the alpha value zero. It is now translucent and you basically have colorkeying in OpenGL.

Share this post


Link to post
Share on other sites
Thanks for the response. I'll try that way right now.

I was hoping there was a way to do it with something like an alpha channel from the image. Not sure if .bmp supports alpha, however, and from the little bit of browsing I did loading a .png seems a bit complex for now.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this