Draw-order based transparency issue

The only way for multiple transparent polygons to render correctly is to draw them from back to front. OpenGL, and, therefore, Processing, don’t know anything about the front to back order of your polygons and so can’t render them as you would like. OpenGL uses a z-buffer to store depth information per-pixel and, when drawing a random triangle, will only draw a given pixel if it is closer to you than (in front of) all the previously seen triangles that overlap that pixel. Transparency breaks this since you can see through a pixel to the triangles behind. The problem comes when you later try to draw a new triangle that falls between previously seen transparent triangles. The z-buffer only knows the depth of closest triangle, whether it’s opaque or transparent, so it assumes the closer pixel must be hiding the new triangle’s pixel and doesn’t show it.

The only way you can handle this is to draw all of your opaque triangles first, in any order, letting the z-buffer order them per-pixel. Then you have to manually sort your transparent triangles based on depth from the camera and draw them into the scene from back to front. If any of your transparent triangles intersect each other, you have to split them along the line of intersection and render the back halves first and then the front halves. It’s a mess.