[英]Model not visible android OpenGL ES 2.0
我目前正在嘗試顯示從Blender導出的模型。 我已經解析了此文件,並具有2個數組,其中一個保存頂點數據,另一個保存索引數據。 我的bindData方法將頂點數據綁定到着色器程序。 我遇到的問題是未繪制小行星(或正在繪制小行星但看不到它們)。 如果需要,我可以提供更多代碼或進一步澄清問題。
public Asteroid(){
vertexArray = new VertexArray(AsteroidFinal.VERTEX_ARRAY);
indexBuffer = ByteBuffer
.allocateDirect(AsteroidFinal.INDICES_ARRAY.length * 2)
.order(ByteOrder.nativeOrder())
.asShortBuffer()
.put((short) AsteroidFinal.INDICES_ARRAY.length);
indexBuffer.position(0);
}
public void bindData(ColorShaderProgram colorProgram){
vertexArray.setVertexAttribPointer(
0,
colorProgram.getPositionAttributeLocation(),
POSITION_COMPONENT_COUNT,
0);
}
public void draw(){
//glDrawArrays(GL_TRIANGLE_FAN, 0, vertexCount);
glDrawElements(GL_TRIANGLE_FAN, AsteroidFinal.INDICES_ARRAY.length, GL_UNSIGNED_SHORT, indexBuffer);
}
看來您沒有將索引存儲在索引緩沖區中:
indexBuffer = ByteBuffer
.allocateDirect(AsteroidFinal.INDICES_ARRAY.length * 2)
.order(ByteOrder.nativeOrder())
.asShortBuffer()
.put((short) AsteroidFinal.INDICES_ARRAY.length);
這會將數組的長度添加到緩沖區,而不是實際的數組值。 它應該是:
indexBuffer = ByteBuffer
.allocateDirect(AsteroidFinal.INDICES_ARRAY.length * 2)
.order(ByteOrder.nativeOrder())
.asShortBuffer()
.put(AsteroidFinal.INDICES_ARRAY);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.