Drawing to Depth Buffer per *pixel* instead of per vertex?

Here’s what I want to do - and I’m not quite sure it’s possible:

I have a Quad with a texture on it… I have it set so that any pixel in the texture that is 255,0,255 (magenta)get’s it’s alpha set to ZERO, any other color pixel gets it’s alpha set to ONE… so this way I can have ‘irregular shapes’ … for example a smiley face surrounded by magenta pixels will show up as just a smiley face when textured onto the quad…

Now here’s the tricky part: Is there any way to set OpenGL so that pixels with alpha of ZERO (ie my magenta pixels, or perhaps more appropriately, texels) do not get drawn to the Depth Buffer? If this is possible it would help me greatly - if not I will have to look into trying to presort (YECH!) these particular (heh, they are particles) Quads…

As it is right now - when quad A goes to draw and discovers that it is behind a another quad, B - quad A doesn’t draw itself in any of the area behind quad B, even though i need it to draw behind some of the area of quad B, namely the pixels in quad B that are magenta …

any suggestions?



Enable alpha testing and use greater than zero as your test. That will prevent the pixels with alpha 0 from being drawn to the color buffer and depth buffer.

Like so:

It works best if you enable it once per frame and then draw all your alpha masked polys in one go, and then disable alpha testing (if there are other polys which are not alpha masked).

[This message has been edited by DFrey (edited 06-13-2000).]


Yeah that did the trick alright, thanks! (It was even in the red book if I had known to look for GL_ALPHA_TEST!)