2012-02-03 81 views
0

我已經使用libgdx完成了一個網格,並且試圖用某種顏色填充網格。在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。

+1

僅供參考,您的頂點和索引不會構成一個立方體。 – 2012-03-13 13:03:43

回答

0

參見http://code.google.com/p/libgdx-users/wiki/MeshColor。您可以使用整個模型的默認顏色或每個頂點的顏色。

在您的示例中,您已經獲得了每頂點顏色信息,因此要更改需要更改頂點的顏色並在網格上重新調用setVertices

+0

我已經解決了這個問題,現在我已經有了一個立方體網格,但是我想在它上面添加一個圖像紋理。 我已經正確加載了紋理,但沒有想法如何將它放在我的立方體頂部。紋理只是一個圖像。 我現在正在使用: \t \t render(GL10.GL_TRIANGLES); 另一個問題是:3D平臺中是否有着色器可用? 謝謝 – user1187691 2012-02-09 17:51:30

+0

請問一個新的問題(當然,搜索後確定它還沒有被問到)。 – 2012-02-09 23:00:21

0

對於在立方體中繪製圖像,在繪製網格之前,必須在渲染方法中添加以下兩行代碼。

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

我們可以爲立方體的每個面繪製不同的紋理嗎? – Dhaval 2012-07-23 13:03:31

相關問題