我目前在Android OpenGL ES 2.0应用程序中遇到一种非常奇怪的行为。 当我想绘制一个从.obj文件中读取的网格时会发生这种情况。 因此很难描述这里的截图
这是我用于加载和渲染网格的sourceCode。场景中应该有一些物体:一个球和一个平台稍微下球(后来球应落下并击中方框)
装载:
public Mesh(FloatBuffer vertexData, int faceCount, int shaderProgram){
this.faceCount = faceCount;
System.out.println("MESH: faceCount " + faceCount);
ByteBuffer bb = ByteBuffer.allocateDirect(8);
bb.order(ByteOrder.nativeOrder());
IntBuffer buffer = bb.asIntBuffer();
GLES20.glGenBuffers(1, buffer);
triangleBuffer = buffer.get(0);
triangleBufferSize = vertexData.capacity();
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, triangleBuffer);
GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, vertexData.capacity() * mBytesPerFloat, vertexData, GLES20.GL_STATIC_DRAW);
//GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
}
这就是我渲染网格的方式:
public void render(int shaderProgram){
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, triangleBuffer);
GLES20.glVertexAttribPointer(GLES20.glGetAttribLocation(RessourceManager.getInstance().getActiveShader(), "vertex"), 3, GLES20.GL_FLOAT, false, 8*mBytesPerFloat, 0);
GLES20.glEnableVertexAttribArray(GLES20.glGetAttribLocation(RessourceManager.getInstance().getActiveShader(), "vertex"));
GLES20.glVertexAttribPointer(GLES20.glGetAttribLocation(RessourceManager.getInstance().getActiveShader(), "normal"), 3, GLES20.GL_FLOAT, false, 8*mBytesPerFloat, 3*mBytesPerFloat);
GLES20.glEnableVertexAttribArray(GLES20.glGetAttribLocation(RessourceManager.getInstance().getActiveShader(), "normal"));
GLES20.glVertexAttribPointer(GLES20.glGetAttribLocation(RessourceManager.getInstance().getActiveShader(), "texCoord"), 2, GLES20.GL_FLOAT, false, 8*mBytesPerFloat, 6*mBytesPerFloat);
GLES20.glEnableVertexAttribArray(GLES20.glGetAttribLocation(RessourceManager.getInstance().getActiveShader(), "texCoord"));
//GLES20.glDrawElements(GLES20.GL_TRIANGLES, faceCount, GLES20.GL_UNSIGNED_SHORT, 0);
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, faceCount*3);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
}
更多信息:我使用的交错数组每个顶点有“VX VY VZ NX NY NZ U V”8个值。 faceCount包含面数。
任何人都可以帮助我并告诉我我做错了什么? (在我的Galaxy Nexus上它正在工作,但在我的HTC One X +上没有,以及在我的Note 10.1上)