OpenGL transparency

You can’t have danger balls without explosions, and you can’t have explosions without transparency. I decided I’d have two types: transparency in textures - for billboarding pictures of dirt being thrown up in the air - and overall transparency of objects - for clouds of semi-transparent smoke.

A simple matter of enabling GL_BLEND, setting a blend function adding an alpha channel to texture images and setting alpha values on object colours…

But what’s this? OpenGL documentation saying there’s more to it…

“When using depth buffering in an application, you need to be careful about the order in which you render primitives. Fully opaque primitives need to be rendered first, followed by partially opaque primitives in back-to-front order. If you don’t render primitives in this order, the primitives, which would otherwise be visible through a partially opaque primitive, might lose the depth test entirely.”

You guys crack me up! How could something so basic necessitate such a contrived algorithm? This must just refer to mid-80s SGI hardware or something…

WAAAAAAAGH!! It’s true! If you don’t draw primitives in the right order it nobbles the whole thing! Come back, Java3D, all is forgiven! I promise I’ll use you in Primate 2.0!

Okay, okay, calm down. I can still use if for explosions, because they get added to the end of the draw list and only last a couple of seconds, so there shouldn’t be any transparencies overlapping. And what kind of a tank game would it be if there was more than one explosion at a time? Ha! I’d like to see that!!

Comments are closed.