繁体   English   中英

在Android上使用libgdx的多维数据集网格

[英]Cube mesh with libgdx on Android

我已经用libgdx制作了一个网格,并且试图用某种颜色填充网格。

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

            bigMesh.setVertices(new float[] {
                    0, -0.5f, -4, Color.toFloatBits(255, 0, 0, 255),
                    1, -0.5f, -4, Color.toFloatBits(255, 0, 0, 255),
                    1, 0.5f, -4, Color.toFloatBits(255, 0, 0, 255),
                    0, 0.5f, -4, Color.toFloatBits(255, 0, 0, 255),

                    1, 0.5f, -3, Color.toFloatBits(0, 255, 0, 255),
                    1, -0.5f, -3, Color.toFloatBits(0, 255, 0, 255),
                    0, -0.5f, -3, Color.toFloatBits(0, 255, 0, 255),
                    0, 0.5f,-3, Color.toFloatBits(0, 255, 0, 255)
                   });   
            bigMesh.setIndices(new short[] { 0, 1, 2, 3,4,5,6,7});
        }
}

render(){
        Gdx.gl.glClearColor(0,0,0,1);
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
        bigMesh.render(GL10.GL_TRIANGLE_STRIP);
}

我应该使用哪个渲染参数? 我正在使用PerspectiveCamera。

要在立方体中绘制图像,必须在渲染方法中添加以下两行代码,然后才能在屏幕上绘制网格。

Gdx.graphics.getGL10().glEnable(GL10.GL_TEXTURE_2D);
texture.bind();

请参阅http://code.google.com/p/libgdx-users/wiki/MeshColor 您可以使用整个模型的默认颜色,也可以使用每个顶点的颜色。

您的示例中具有按顶点的颜色信息,因此要更改颜色,需要更改顶点,然后重新调用网格上的setVertices

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM