Sign in to follow this  
Floware

Transparency problem

Recommended Posts

HI I'm kind a stuck here. I try to use simple transparency, should work fine, but it doesn't. I use the following code to do it: glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_DECAL); glBindTexture(GL_TEXTURE_2D, Text[0]); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_QUADS); glTexCoord2f(0.0f,1.0f); glVertex3f(0,0,PosZ); glTexCoord2f(1.0f,1.0f); glVertex3f(SizX ,0,PosZ); glTexCoord2f(1.0f,0.0f); glVertex3f(SizX,-SizY, PosZ); glTexCoord2f(0.0f,0.0f); glVertex3f(0, -SizY, PosZ); glEnd(); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); So, the texture is in RGBA, and i want it transparent at the pixels/texels where the alpha is 0. The problem i have and do totally not understand is, that the blending seems to work, but instead of that i see the background(or what i did draw at that position before i did the blending) shines through, the transparent part is filled with the last color used, that was set with glColor3f/4f(..) before. actually the same happens, if i don't use blending at all and just draw the texture with rgba to the screen. Always it seems to be transperent, but not the 'behind' is showing. The last used/selected color fills the transparent parts. I've no idea why this happens, and no idea how to fix anything about it. I don't understand, all the tutrials i looked up, the don't do anything different (or I'm just to stupid to see it, till now, at least) Thanks for any help. Flo

Share this post


Link to post
Share on other sites
Ive the same problem I replaced this:
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_DECAL);
with this
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_REPLACE);
Iam not totally sure what it does but it seems to work.
Maybe someone can tell me?.
I use GL_ALPHA_TEST but I think it should work with blending as well

hope it helped!

Share this post


Link to post
Share on other sites
Edit - ignore this:
Nothing obvious is wrong with the code you posted. One thing that could be the problem, is the rendering order. Transparent triangles write into the z-buffer like any other triangle. If the transparent object is drawn before the objects behind it, the latter will not actually be drawn into the area behind the quad. A solution to this, is drawing the transparent object last. If there are more transparent objects, the solution will be (much) more complex.
This is not necesseraly the problem you are facing, though.

Edit - read this instead:
I should read better. The solution in the first reply might work. For RGB GL_DECAL is equal to GL_REPLACE. However, for RGBA they have different mechanics:
GL_REPLACE does the replacement you want, GL_DECAL also uses the color of your quad (the color C is: Cquad*(1-alpha) + Ctexture*alpha). If the alpha of the texture is 0, the color at those positions will be Cquad*1.0 + Ctexture*0.0 = Cquad. If you don't specify colors for the quad, this color will be the color of the previous object...

Tom

[Edited by - dimebolt on July 11, 2005 11:23:07 AM]

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