简体   繁体   English

模型不可见android OpenGL ES 2.0

[英]Model not visible android OpenGL ES 2.0

I am currently trying to display my model I exported from blender. 我目前正在尝试显示从Blender导出的模型。 I have parsed this file and have 2 arrays, one of which holds the vertex data and the other holds the index data. 我已经解析了此文件,并具有2个数组,其中一个保存顶点数据,另一个保存索引数据。 My bindData method binds the vertex data to the shader program. 我的bindData方法将顶点数据绑定到着色器程序。 The problem I am encountering is that the asteroid is not being drawn(or they are being drawn but cannot see them). 我遇到的问题是未绘制小行星(或正在绘制小行星但看不到它们)。 I can provide more code or clarify my problem further if needed. 如果需要,我可以提供更多代码或进一步澄清问题。

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);
}

It looks like you're not storing the indices in the index buffer: 看来您没有将索引存储在索引缓冲区中:

indexBuffer = ByteBuffer
        .allocateDirect(AsteroidFinal.INDICES_ARRAY.length * 2)
        .order(ByteOrder.nativeOrder())
        .asShortBuffer()
        .put((short) AsteroidFinal.INDICES_ARRAY.length);

This adds the length of the array to the buffer, not the actual array values. 这会将数组的长度添加到缓冲区,而不是实际的数组值。 It should be: 它应该是:

indexBuffer = ByteBuffer
        .allocateDirect(AsteroidFinal.INDICES_ARRAY.length * 2)
        .order(ByteOrder.nativeOrder())
        .asShortBuffer()
        .put(AsteroidFinal.INDICES_ARRAY);

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

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