1

是否可以使用libgdx在opengl 1.1中的预着色网格上着色或设置alpha?

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);
}

我会使用纹理,我可以使用 glColor4f 添加阴影或设置透明度,但是如果我使用顶点颜色,那么我不能这样做吗?

4

0 回答 0