Hi. I’ve created a method for rendering meshes using vertex arrays and glDrawElements function. Here it is:
public static void draft(Mesh3D mesh) {
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
FloatBuffer buf = Buffers.wrap(mesh.getVertices());
GL11.glVertexPointer(3, 0, buf);
IntBuffer ibuf = mesh.getVertexIndices();
GL11.glDrawElements(GL11.GL_TRIANGLE_STRIP, ibuf);
GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
}
When I use the method, nothing happens, although I can’t find any errors in the code above.
But if I use the glArrayElement combination instead, my mesh renders correctly. Here is a slightly corrected version of the previous code.
public static void draft(Mesh3D mesh) {
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
FloatBuffer buf = Buffers.wrap(mesh.getVertices());
GL11.glVertexPointer(3, 0, buf);
IntBuffer ibuf = mesh.getVertexIndices();
GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
for(int i = 0, n = ibuf.capacity(); i < n; i++) {
GL11.glArrayElement(ibuf.get(i));
}
GL11.glEnd();
GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
}
Could you explain what I am doing wrong? Why doesn’t my first code work?
