I want to draw two textures on two planes. Both should be partially transparent. So it should be possible to see e.g. plane a through the transparent region of plane b.

This works good, if I use:
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0);

But if I use:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
instead it only works from one direction. It is only possible to see the first drawn plane through the second drawn plane.

So it depends on which plane is drawn first.
I enabled GL_DEPTH_TEST.

Does someone has an idea why it doesn't work?

Thank you for your help,

Michael

Alfonse Reinheart

10-27-2009, 05:03 PM

I enabled GL_DEPTH_TEST.

That's why.

Alpha test is not the same as blending. Alpha test actually culls the pixels, so that the depth buffer never gets written. It punches holes in the polygon, so to speak. Blending is simply combining one color with whatever happened to be there at the time.

If you draw one polygon behind another with depth test on, it culls the pixels from the second polygon because their depth value is farther away. This doesn't stop happening just because you turn on blending.

This is why, when you use blending, you must sort all triangles by depth. And you must turn off depth testing.

Michaeil02

10-28-2009, 06:30 AM

Thanks a lot. So there is no other way to do this but ordering or using the glAlphaFunc?

Thanks a lot,

Michael

DmitryM

10-28-2009, 06:44 AM

Usually I disable depth writing (glDepthMask(0)) for transparent objects, keeping depth testing on.
This will guarantee both transparent planes to be drawn in your case.