1

Is it way to colorize or set alpha at precolored mesh in opengl 1.1 with libgdx?

private Mesh mesh;
private Camera camera;
@Override
public void create() {          
    if (mesh == null) {
        mesh = new Mesh(true, 3, 1, 
                        new VertexAttribute(Usage.Position, 3, "a_position"),
                        new VertexAttribute(Usage.ColorPacked, 4, "a_color"));

        mesh.setVertices(new float[] {  -1f,0f,0.000000f,Color.toFloatBits(255,0,0,255),
                                        1f,0f,0.000000f,Color.toFloatBits(0,255,0,255),
                                        0f,1f,0.000000f,Color.toFloatBits(0,0,255,255)
                                    });

        mesh.setIndices(new short[] { 0,1,2});
    }
}
@Override
public void render() {
    GL11 gl = Gdx.graphics.getGL11();
    gl.glEnable(GL10.GL_DEPTH_TEST);
    gl.glDepthFunc(GL10.GL_LESS);     

    camera.update();
    camera.apply(Gdx.gl10);

    gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    gl.glClearColor(0.15f, 0.15f, 0.15f, 1);
    gl.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);    

    gl.glEnable(GL11.GL_BLEND);
    gl.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    gl.glShadeModel(GL11.GL_SMOOTH);

    gl.glPushMatrix();
    //blue overlay + 50% opaque
    gl.glColor4f(0f,0f,1f,0.5f);    //*** THIS LINE IS IGNORED
    mesh.render(GL10.GL_TRIANGLES, 0, 3);
    gl.glPopMatrix();
}
@Override
public void resize(int width, int height){
    float aspectRatio = (float) width / (float) height;
    camera = new OrthographicCamera(10f * aspectRatio, 10f);
}

I'd use textures I can use glColor4f to add shade or set the transparency, but if I use vertex colors then I can't do that?

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Kevin Good
  • 11
  • 1
  • 2

0 Answers0