Transparency problem

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

Try

glTexEnvf(
GL_TEXTURE_ENV,
GL_TEXTURE_ENV_MODE,
GL_MODULATE
);

This is the default mode.

If you look at the chart in the spec or the redbook you’ll see that with GL_DECAL the enviroment alpha is equal to the previous environment alpha, which for environment 0 is the incoming primary alpha. In other words, I think you are using the current vertex alpha (glColor*()), not the alpha in the texture.

Modulte will give you the product of the previous environment and the texture, which I think is what you want. In your case it will scale the texture alpha by the current (interploated) vertex alpha.

Look at page 184 of the 2.0 spec.

Hlz

Thanks for an answer, but that’s not what i want.
{i tried it}

What I want is: each pixel should be calculated like that: ((1-As)Rd + As *Rs), …

What i don’t understand, Why does the Color, which is set before with Color4f(…), does influence that blending at all??? I don’t wanna have this color messing around there at all.
All that should influence the is the Pixels in the framebuffer and the texture. Why there’s the other color, how does it come into this game. I don’t see it and don’t understand that.

I wanna see the background shine through and not that stupid color.

it should be so simple. I just don’t get where my mistake is.

maybe your geometry should also be transparent.

I am a bit lost with the description of your problem. Can you post a picture ?

Be sure to call
glColor4f(1.0f,1.0f,1.0f,1.0f);
before rendering your blended quad.

Maybe these artifacts are due to unwanted depth test ? disable it, just to see.

Thx for all the answers.

  1. I call color4f(1.0f … 1.0f), but is this important,(i did post it here cause did comment it out, for test resons, it doesn’t change a thing)?

  2. What does it mean my geometrie has also be transparent??

  3. I found out so far, Texture Env, should be GL_REPLACE, cause then the fragment Color does not influence the texture, at all.
    But then the Problem remains, just the parts in the texture, where A is less than 1.0 always white shine through and where A=0.0 the pixels are white, I expect there to be what has been there before. If i blend a texture with some texel with Aplha = 0, the pixel in the framebuffer,(the a=0 texels are rendered to) should NOT be changed at all?? Or am I wrong?

Somethings missing or doesn’t work right. When I look at the formel I chose for the blending and how texture and fragment color is handelt. I don’t see, why there is white appearing, at the places, where it should be transparent.

The depht test is disabled, and the order of the drawing is as i want it to be.

In this case it does matter cause i’m drawing just one quad, so I think at the texels with aphla = 0, the clearcolor (cause thats what is in the framebuffer now, in this case i chose black) should stay, but it is painted white. The Texel has alpha=0, so why does opengl makes the pixel in framepuffer
white and does not leave it like it is.

In the cases where A=0-1.0 it should blend it over the black from the framebuffer (or whatever is written there before i do this, at this position)
But it is blended with white.

It all looks like there is a quad drawn, with the same size as the textures quad, painted white, and over that is the texture blended as i want it to.

I can try to make some picture and post it here tomorrow.

Thanks for any help, I haven’t been that stuck for a long time.

Flo

  1. I found out so far, Texture Env, should be GL_REPLACE, cause then the fragment Color does not influence the texture, at all.
    That’s a good option. But realize that GL_MODULATE with glColor4f(1,1,1,1) will produce the same result, only with modulate you have the added flexibility of being able to scale the result any way you want. Just so you know…

Just a shot in the dark but are you sure your texture contains the alpha you think it does. I’ve had textures I thought were right only to find out later after plenty anguish I was dead wrong about it…

There are working examples in the redbook (and elsewhere) that demonstrate blending like this. You’re right, it shouldn’t be this difficult. It should just work.

Hlz

When in doubt, consider posting the complete source or a simple GLUT test case.

Simple mistakes are easy to catch this way…

ok, somehow it works now fine, i cannot even reproduce the mistake again, and i didn’t change anything, or didn’t try anything i didn’t tried already before.
Maybe there’s some f**k uo with windows or the ogl drivers… whatever.

thanks for answers.