Building open this tutorial - https://code.google.com/p/libgdx/wiki/ProjectionViewportCamera I have constructed a class for generating polygon meshes. But i cannot figure out how to render semi transparency, even though the mesh in the tutorial takes a color object with an alpha channel.

I am rendering with squareMesh.render(GL10.GL_TRIANGLE_STRIP, 0, 4); This is the code used for initializing the mesh

if (squareMesh == null) {
    squareMesh = new Mesh(true, 4, 4, 
                 new VertexAttribute(Usage.Position,    3, "a_position"),
                 new VertexAttribute(Usage.ColorPacked, 4, "a_color"));

    squareMesh.setVertices(new float[] {
        -0.5f, -0.5f, 0, Color.toFloatBits(128, 0, 0, 255),
         0.5f, -0.5f, 0, Color.toFloatBits(192, 0, 0, 255),
        -0.5f,  0.5f, 0, Color.toFloatBits(192, 0, 0, 255),
         0.5f,  0.5f, 0, Color.toFloatBits(255, 0, 0, 255) });   
    squareMesh.setIndices(new short[] { 0, 1, 2, 3});

In Color.toFloatBits(128, 0, 0, 255), the "255" is the alpha channel (where 255 means completely opaque and 0 means completely transparent = invisible).
Make sure you've enabled transparency in OpenGL with


to disable transparency again, simple use Gdx.gl.glDisable(GL10.GL_BLEND);


I found that ModelBatch.begin(...) will disable Blending by calling Gdx.gl.glDisable(GL20.GL_BLEND). So make sure to enable blending AFTER calling ModelBatch.begin().

modelBatch.begin(camera); // resets Blending to false
// enable Blending
// draw mesh
mesh.render(shader, GL20.GL_TRIANGLES);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.