One More Transparency Trick

Here's another trick for dealing with the drawing-order problem of multiple transparent objects: use glDepthMask().

With glDepthMask(GL_FALSE), you can have OpenGL use the depth test to determine whether or not to draw a new pixel, but not update the depth buffer. This means that it will retain the depth information from whatever was drawn before glDepthMask(GL_FALSE) was called, and only use that in the depth test; new objects will not occlude anything. Remember to call glDepthMask(GL_TRUE) when you've finished drawing the transparent objects.

By disabling depth-buffer writing while drawing transparent objects, you can guarantee that they won't occlude each other, and will all be blended together.

It's not a perfect solution, as the exact results of the blending will still depend on the order that things are drawn. But, the errors are not as jarring as when one transparent object completely occludes another.

Also, this method is only useful for translucent objects - it won't work for "cutout" transparency.

Example code: drawOrder2.c