# OpenGL Transparency Bit Planes problem

This topic is 4225 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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);
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 on other sites
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 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 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.

1. 1
2. 2
3. 3
Rutin
20
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633655
• Total Posts
3013175
×