【问题标题】:Cube mesh with libgdx on Android在 Android 上使用 libgdx 的立方体网格
【发布时间】:2012-02-03 14:35:33
【问题描述】:

我已经用 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。

【问题讨论】:

  • 仅供参考,您的顶点和索引不构成立方体。

标签: java libgdx mesh perspectivecamera cubes


【解决方案1】:

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

您在示例中获得了每个顶点的颜色信息,因此要更改颜色,您需要更改顶点,然后在网格上重新调用 setVertices

【讨论】:

  • 我已经解决了这个问题,我现在有一个立方体网格,但是我想在上面添加一个图像纹理。我已经正确加载了纹理,但不知道如何将它放在我的立方体上,在顶面上。纹理只是一个图像。我现在使用渲染:render(GL10.GL_TRIANGLES);另一个问题是:是否有任何着色器可用于 3D 平台?谢谢
  • 请提出一个新问题(当然,在搜索以确保尚未被问到之后)。
【解决方案2】:

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

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

【讨论】:

  • 我们可以为立方体的每个面绘制不同的纹理吗?
猜你喜欢
  • 2012-04-04
  • 2017-05-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-18
  • 2012-06-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多