texture blending problems...

Hello all,

I am trying to blend 2 textures (applied to the same plane), both of which contain transparent areas.

The way I do it now is with two passes:
if(pass==0)
{
glBindTexture(GL_TEXTURE_2D, openGLName[0]);
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);

glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_REPLACE );
}
else
{
glBindTexture(GL_TEXTURE_2D, openGLNam [1]);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);

glBlendFunc(GL_DST_ALPHA,GL_ZERO);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
}
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_NOTEQUAL,0);

I first apply the first texture and on top of it I blend the second. What seems to happen though is that the second texture covers and hides the transparent regions of the first one, something that shouldn’t happen with a (GL_DST_ALPHA,GL_ZERO) blending function.

Am I right, or if not what am I doing wrong??

Thanks a lot for any help!!

Kostas.

you should read up on the equation on blendFunc

glBlendFunc(GL_DST_ALPHA,GL_ZERO);

that will be srcFragment*destAlpha + destFragment(the frame buffer)*0

so you will replace everything on the screen with srcfragment*destAlpha, and if destAlpha isnt present ( very common on older cards) i think you will get 1 there every time, so basically youre replacing the framebuffer with the new texture.

i think you want
(srcFragment * srcAlpha) + (destFragment * invsrcAlpha)

that is
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);