简体   繁体   English

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

[英]Cube mesh with libgdx on Android

I've done a mesh with libgdx and I'm trying to fill the mesh with some color. 我已经用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);
}

Which render paremeter shall I use? 我应该使用哪个渲染参数? I'm using PerspectiveCamera. 我正在使用PerspectiveCamera。

For drawing images in the cube you have to add following two lines of code in your render method before drawing mesh on the screen. 要在立方体中绘制图像,必须在渲染方法中添加以下两行代码,然后才能在屏幕上绘制网格。

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

See http://code.google.com/p/libgdx-users/wiki/MeshColor . 请参阅http://code.google.com/p/libgdx-users/wiki/MeshColor You can either go with a default color for a whole model, or a per-vertex color. 您可以使用整个模型的默认颜色,也可以使用每个顶点的颜色。

You've got per-vertex color information in your example, so to change the color you need to change the vertices, and re-invoke setVertices on the mesh. 您的示例中具有按顶点的颜色信息,因此要更改颜色,需要更改顶点,然后重新调用网格上的setVertices

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

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