Pergunta

This is how I turn on ortho projection after drawing 3D objects:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,Screen_Width,Screen_Height,0,0,1);

And this is how I turn on blending and draw textures in ortho after drawing 3D objects:

glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); 
glColor4f(1,1,1,1);

glBindTexture(GL_TEXTURE_2D,Texture1);
glBegin(GL_QUADS);
//draw 1st quad
glEnd();

glBindTexture(GL_TEXTURE_2D,Texture2);
glBegin(GL_QUADS);
//draw 2nd quad
glEnd();

glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);

Quad1 is a bit larger than Quad2 and covers some parts of Quad2. Both textures have alpha channel as RGBA.

The problem is, Quad1 & Quad2 overlay the 3D objects with alpha correctly, but the alpha of Quad1 doesn't work when being on top of Quad2. It draws on top of Quad2 like RGB only.

How could I solve this problem?

Foi útil?

Solução

Is depth buffering enabled? If it is, that could cause fragments to be discarded (failing the Z test) instead of alpha-blended with what's already there.

If you're using a depth buffer, you need to draw transparent objects in back-to-front order.

For a purely 2D scene, you might not even need a depth buffer, and you can just turn it off:

glDisable(GL_DEPTH_TEST);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top