Jump to content
  • Advertisement
Sign in to follow this  
MightyMartin

OpenGL Transparency Bit Planes problem

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

Hello all. Right now, I'm currently porting my friend's small library, which given to openGL programmers' functionality to load various image format. His library is working successful in Delphi (Pascal) language, so that I want to use it also in C++ environment. Right now I'm working on the Targa files. Assumed that the load function for the Targa image is successful, 32 bit, uncompressed Targa, and it's already reached the gluBuild2DMipmaps with GL_RGBA_EXT, what I want to ask is why I can't make the transparent part on the Targa image transparent when it's drawn on the openGL window? -- the image is drawn nicely, except that every transparent part on the image (the one that the alpha value isn't 255) becomes solid as if all of the alpha value of the pixels becomes 255. I'm using GLUT, already specifying GLUT_RGBA when initializing the GLUT. I've already activated the 2D texture feature - glEnable (GL_TEXTURE_2D). I've already activated the blending feature - glEnable (GL_BLEND). and I've already specifying the blending function - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) and the code I used to draw is:
glBindTexture (GL_TEXTURE_2D, ftargatexture); 
// ftargatexture is where I put the texture ID
glColor4f (1, 1, 1, 1);
glBegin (GL_QUADS);
glTexCoord2f (0, 0); glVertex2f (0, 0);
glTexCoord2f (1, 0); glVertex2f (1, 0);
glTexCoord2f (1, 1); glVertex2f (1, 1);
glTexCoord2f (0, 1); glVertex2f (0, 1);
glEnd();
I think that there is nothing wrong with drawing codes, because the image is drawn correctly. I just can't make the transparent part of the image transparent in openGL window. But if I change alpha value in glColor4f with 0.5, all of the image is transparent 50%. It means that the blending function works correctly. But, why? Is there something I missing? Thanks in advance. Martin

Share this post


Link to post
Share on other sites
Advertisement
When you enable blending with glEnable(GL_BLEND), you must disable it when you are finished with it via glDisable(GL_BLEND), or else you will get a global blending affect on all objects which you've already noticed. Similarly with GL_TEXTURE_2D, be sure to disable that when you're done as well, along with any lighting you may be doing. And, with glColor4f, if you set the fourth value to 0.5f, you need to reset that as well by either resetting the coloring or simply calling glColor4f again with 1.0f as the fourth parameter.

In OpenGL, as a rule of thumb: undo what you do. :)

Share this post


Link to post
Share on other sites
hi Omega147, thanks for the reply.

Btw, what I'm actually trying to achieve is drawing an image with transparency on part of it, such as in cases like: I want to draw a bunny object in front of a home background. I give transparent alpha channel on the rectangular part of the bunny image, so that only the bunny image is drawn on the screen, not including the white rectangular of the image (the background of the bunny image).

From what I learnt, image transparency is only available if the glBlend is activated and glBlendFunc is set on (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). I just try to ensure that glBlendFunc is working, so that I set the glColor4f to (1, 1, 1, 0.5), and the "global" image transparency is work. But I can't set the individual pixel's alpha information taken from the Targa image files to be working.

Is there something I missing while working with image transparency?

edit: dumb typo

Share this post


Link to post
Share on other sites
Quote:
Original post by MightyMartinBtw, what I'm actually trying to achieve is drawing an image with transparency on part of it, such as in cases like: I want to draw a bunny object in front of a home background. I give transparent alpha channel on the rectangular part of the bunny image, so that only the bunny image is drawn on the screen, not including the white rectangular of the image (the background of the bunny image)

To achieve this partial transparency effect that you're after, you'll have to look into what's called "masking." This is an effect achieved by mapping one image onto another, in essence, where the second image defines which portions of the first image are to be shown (or vice versa).

NeHe has a tutorial on masking here, although, I don't think that tutorial will give you the exact solution you're after. But it's a start.

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!