Thursday, January 28, 2010

Jogl: Texture Transparency

So here's another JOGL example for drawing transparent textures. The code is a bit lengthy but the comments should help guide you to the important parts.

The most important piece of code is turning on blending.

// Really basic and most common alpha blend function


gl.glBegin(GL.GL_QUADS); // the gl draw mode
One thing you must note here is that the texture binding is done outside the glBegin and glEnd calls as well as telling the device to turn on blending and setting the blend function.

Other code to note is the creation of a texture from a BufferedImage, which is covered in a previous post so take a look at that first, Drawing HTML with JOGL Part 1: Textures. This example is based off of that code.

NOTE: Also, be sure to pay close attention to the order in which transparent textures are drawn.

And now the code:
This example uses JOGL version 1.1.1a and should work with the NetBeans plugin you can obtain the version from JOGL's website go to the "Archived Builds" page from the navigation menu on the left. Then find the jsr-231-1.1.1a folder


Anonymous said...

I never remember even the simplest of things when I start fooling around with this stuff even after a small break. That being said, you made an anon happy today, now you can pat yourself on the back.

MorbidMorvick said...

Lolz, this is the reason I started the blog in the first place. I usually forget specific settings or calls when I haven't had to redo the basic setup code in a while or needed to tweak anything.

Also appreciate the permission for the patting on the back, lolz! You've made my morning, thank you, you may also pat yourself on the back.

Post a Comment