Jump to content
  • Advertisement
Sign in to follow this  
wangdiweilu

how to use glblendfunc to transperent background

This topic is 4050 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 render a quad by loading a .tga picture as texture;the picture’s background is white and there is a sign in the middle of the picture. I want to display the sign and don’t display the background .how to use glblendfunc to do it

Share this post


Link to post
Share on other sites
Advertisement
I assume your texture has alpha channel. An alpha channel is used to mask stuff out of the image.

If your texture has alpha then this will enable alpha-blending.


glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glEnable( GL_BLEND );


Here's some recent threads...

An alpha enabled tga loader in code tags...
http://www.gamedev.net/community/forums/topic.asp?topic_id=455716


And here's some info how to create alpha TGAs
http://www.gamedev.net/community/forums/topic.asp?topic_id=455701

[Edited by - pieslice on July 15, 2007 3:40:22 PM]

Share this post


Link to post
Share on other sites
If you load the textures on your own (you have the source code for the textureloading function) you could also use color-keying, i.e. specify a color that is transparent. This way you could get a texture where the pixels are either fully transparent or fully opaque.

I do it the following way (image loading and texture creation):
-if color key is used
 -for each pixel in the image
  -if pixel color matches color key
   -set alpha value of pixel to 0
  -else
   -set alpha value of pixel to 1
-else
 -for each pixel in the image
  -set alpha value of pixel to 1 (or use alpha channel)

After this you have a pixel array that you pass to OpenGL to create the texture object. Don't forget, however, that your OpenGL texture should use a format that includes an alpha channel.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!