Hey there
after having decided to increase my modelloader’s performance and thus having implemented displaylists, i now changed to VBOs. Sadly they don’t work out…
I simply don’t get my mistake, although i have browsed a lot of tuts and specs…
I calculate the VBO:
VBOVertices = new int[1];
VBOIndices = new int[1];
int vertexCount = meshes[0].faces.length*3;
gl.glGenBuffersARB(1, VBOVertices, 0);
gl.glGenBuffersARB(1, VBOIndices, 0);
gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, VBOVertices[0]);
gl.glBindBufferARB(GL.GL_ELEMENT_ARRAY_BUFFER_ARB, VBOIndices[0]);
FloatBuffer tmpFBuffer = FloatBuffer.allocate(meshes[0].vertices.length*3);
for (int i=0; i < meshes[0].vertices.length; i++)
{
tmpFBuffer.put(meshes[0].vertices[i].vector.x);
tmpFBuffer.put(meshes[0].vertices[i].vector.y);
tmpFBuffer.put(meshes[0].vertices[i].vector.z);
}
tmpFBuffer.flip();
gl.glBufferDataARB(GL.GL_ARRAY_BUFFER_ARB, meshes[0].vertices.length * 3 * BufferUtil.SIZEOF_FLOAT, tmpFBuffer, GL.GL_STATIC_DRAW_ARB);
IntBuffer tmpIBuffer = IntBuffer.allocate(meshes[0].faces.length*3);
for (int i=0; i < meshes[0].vertices.length; i++)
{
tmpIBuffer.put(meshes[0].faces[i].v1);
tmpIBuffer.put(meshes[0].faces[i].v2);
tmpIBuffer.put(meshes[0].faces[i].v3);
}
tmpIBuffer.flip();
gl.glBufferDataARB(GL.GL_ELEMENT_ARRAY_BUFFER_ARB, meshes[0].vertices.length * 3 * BufferUtil.SIZEOF_FLOAT, tmpIBuffer, GL.GL_STATIC_DRAW_ARB);
VBOCalculated = true;
and render it:
if (!VBOCalculated)
return;
gl.glDisable(GL.GL_TEXTURE_2D);
gl.glDisable(GL.GL_LIGHTING);
gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, VBOVertices[0]);
gl.glBindBufferARB(GL.GL_ELEMENT_ARRAY_BUFFER_ARB, VBOIndices[0]);
gl.glInterleavedArrays(GL.GL_V3F, 0, 0);
gl.glDrawElements(GL.GL_TRIANGLES, meshes[0].faces.length*3, GL.GL_UNSIGNED_INT, 0);
gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
Though the screen remains black. Do you have any hints?
Thanks in advance