[英]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.