# Texture with transparency not rendered correctly in LibGDX

The title might be a bit misleading but I'm having a hard time to explain the problem so I'll try with pictures:

Same tree from opposite site:

I'm trying to create a voxel game and at the moment I try to get textures with transparency working. The mesh is generated for each chunk individually so that every chunk has its own ModelInstance that is rendered.

And the result should be like in the second picture (almost) so that every block is rendered behind the transparent textures but thats not the case for every side.

The relevant code for the transparent textures:

        Mesh mesh = new Mesh(true, meshDataBlended.sizeEstimate, (int)Math.round(meshDataBlended.sizeEstimate * 1.5),
new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));

BlendingAttribute blendingAttribute = new BlendingAttribute();
blendingAttribute.blended = false;
blendingAttribute.sourceFunction = GL20.GL_SRC_ALPHA;
blendingAttribute.destFunction = GL20.GL_ONE_MINUS_SRC_ALPHA;

mesh.setVertices(meshDataBlended.vertices);
mesh.setIndices(meshDataBlended.indices);

Node terrainNode = modelBuilder.node();
terrainNode.id = "terrain_blended";

modelBuilder.part(
"terrain_blended", mesh, GL20.GL_TRIANGLES,
new Material(TextureAttribute.createDiffuse(World.TEXTURE), blendingAttribute)
);


I'm pretty new to OpenGL, so I'm totally lost with this problem. No idea why it behaves like this and I even don't know where I could find the needed informations. So far i just know that it depends on what is rendered first (that's why it works from one side but not the opposite side) Sorry for using Minecraft textures it's just for testing purposes.

Let me know if some additional information is needed I'll add them then.

Thanks Blakk

EDIT: setting blended to true will make everything visible behind the leaves except other leaves (still only from specific sides).

Solved the problem by writing my own shader which now renders the mesh with the transparent textures.

#ifdef GL_ES
precision mediump float;
#endif
varying vec2 v_texCoords;
uniform sampler2D u_texture;

void main() {

vec4 texel = texture(u_texture, v_texCoords);
if (texel.a < 0.5) {
}

gl_FragColor = texel;
}


Render function:

public void render(ShaderProgram solidShader, ShaderProgram transparentShader) {
Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);
Gdx.gl.glEnable(GL20.GL_CULL_FACE);
World.TEXTURE.bind();

//Render transparent mesh

//Render solid mesh

Gdx.gl.glDisable(GL20.GL_DEPTH_TEST);
Gdx.gl.glDisable(GL20.GL_CULL_FACE);
}