LWJGL Problem Transparent Textures in 3D

Hey, as the Title says i’m using Textures in 3D and some of them have Transparent pixels.
Here my init Code:

GL11.glMatrixMode(GL11.GL_PROJECTION);
		GL11.glLoadIdentity();
		GLU.gluPerspective(60, Display.getWidth()/Display.getHeight(), 0.001f, 64);
		GL11.glMatrixMode(GL11.GL_MODELVIEW);
		GL11.glLoadIdentity();
		// Depth Test
		GL11.glDepthFunc(GL11.GL_LEQUAL);
		GL11.glEnable(GL11.GL_DEPTH_TEST);
		// Texture
		GL11.glEnable(GL11.GL_TEXTURE_2D);
		// Transparent Faces
		GL11.glEnable(GL11.GL_BLEND);
		GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
		// Transparent Textures
		GL11.glEnable(GL11.GL_ALPHA_TEST);
		GL11.glAlphaFunc(GL11.GL_GREATER, 0);
		// Enable Cull Face
		GL11.glEnable(GL11.GL_CULL_FACE);
		GL11.glCullFace(GL11.GL_BACK);
		GL11.glClearColor(0.2f, 0.5f, 0.8f, 1.0f);

However, I got like a Cube and want to put a name above it, Using an Image which contains all Letters. The text itself works fine, The Cube itself works fine too but The Text has the problem that the transparent faces aren’t really transparent, they just get coloured as my Clear Color ( In this case 0.2, 0.5, 0.8 ) Which isn’t really what i wanted as you might guess. So when there’s like a world behind that name there isn’t just the Text, it’s the text with a border in the clearcolor as if the texture wasn’t transparent and contained the Color which it doesn’t. however in 2D it’s working fine where i got exactly the same init code for the Textures.

transparency just cutting through the cube (Or Lots of Cubes cause it’s actually 9x15x9 Cubes which will later be represented by a character)

It Looks like this:

Oh, right okay, when i change


      GL11.glAlphaFunc(GL11.GL_GREATER, 0);

to


      GL11.glAlphaFunc(GL11.GL_GREATER, 0.1f);

it works haha thanks man :smiley:

But this works only if the alpha value of those are 0, any chance i can get this work for all alpha values?
looks better but there is still some Blue lines arround it :smiley:

You can sort your scene (draw non-transparent objects first) and set glAlphaFunc to very low value (like 0.000001f).

Allright, if I draw the non Transparent Faces first and the Transparent stuff after that it works perfect :slight_smile: even with


      GL11.glAlphaFunc(GL11.GL_GREATER, 0);

And that’s just for the name of the Character so that’s totally ok :smiley:

glAlphaFunc completely “hide” parts of mesh with alpha smaller than threshold (at least in your case, because this depends on first argument). Even if you don’t sort your scene you shouldn’t see any artifacts. I recommend setting it to GL_NOTEQUAL and set the value to 0, then everything with 0 alpha (invisible) will be hidden.

When you use glBlendFunc, you must sort your scene, because rendering order IS important. Think about this like about taking pictures: when you make picture of empty table and then place mug on it, the mug will not appear in the picture because picture is already made.

I’m not using any glBlendFunc things atm and i think i will remove this from the initcode because my Voxel Modellloader+creator (Made them by myself ;D ) doesn’t support them and it looks good like it is without transparent cubes there :smiley: