Z-Depth Testing in OpenGL
graphics, opengl
Solution
Good question.
The short answer is that the Z-buffer stores a single value (only) for each pixel in the frame buffer. Given the "usual" mode of operation (for opaque objects--`GL_DEPTH_TEST` enabled, `glDepthFunc` set to `GL_LESS`), that value will be the depth of the nearest fragment that maps to that pixel.
The frame buffer is a "dumb" device--every fragment rasterizes and depth tests independently from all others, and divorced from any concept of the primitive that produced it. So, there is no place for the information about preceding primitives, depth sorting, etc. to be held, as would be required to implement your "auto transparency" feature.
You might want to look into "scene graphs" for help with the depth sorting. These are libraries that add "higher level" functionality beyond the basic T&L stuff that OpenGL provides.
Hope this helps.
Problem
first time here. Sitting down today and teaching myself OpenGL. But I have run into a question I can't seem to find the answer to. I'm wondering why depth testing seems to be incompatible with semi-transparent objects in OpenGL. The documentation seems to suggest that you must turn off depth-testing, then draw objects in reverse-distance order and the blending will work properly. But why can't openGL just use the same depth test it always does to figure out what's furthest back in reverse distance order and do this for you? Is it just a limitation of the framework, or is it something to do with what you can do efficiently in graphics hardware, or something like that? Just wondering. Hope someone here can elucidate.