Hi
To prevent others making the same mistake id did, I am going to request some clarity to be added the javadoc for glDrawElements
glDrawElements
public static void glDrawElements(int mode,
int count,
int type,
long indices)
Reference Page
Constructs a sequence of geometric primitives by successively transferring elements for count vertices to the GL. The ith element transferred by DrawElements will be taken from element indices[i] (if no element array buffer is bound), or from the element whose index is stored in the currently bound element array buffer at offset indices + i. I have posted the java doc for the function in question below.
Parameters:
mode - the kind of primitives being constructed. One of:
POINTS LINE_STRIP LINE_LOOP LINES POLYGON TRIANGLE_STRIP TRIANGLE_FAN
TRIANGLES QUAD_STRIP QUADS LINES_ADJACENCY LINE_STRIP_ADJACENCY TRIANGLES_ADJACENCY TRIANGLE_STRIP_ADJACENCY
PATCHES
count - the number of vertices to transfer to the GL
type - indicates the type of index values in indices. One of:
UNSIGNED_BYTE UNSIGNED_SHORT UNSIGNED_INT
indices - the index values
]
The confusion here is the long indicies value.
Firstly, it is not the index values. The index values are stored in the ELEMENT ARRAY_BUFFER as there is no way to pass one in this call.
Secondly the indicies value is the offset in to the ELEMENT_ARRAY_BUFFER, but this is the byte offset and not the offset of the number of elements in the array. I'll explain more with the below example
ELEMENT_ARRAY_BUFFER = {0,1,2,3,4,5}
Lets say I want to draw use the first three to draw a triangle
GL11.glDrawElements(GL11.GL_TRIANGLES,3,GL11.GL_UNSIGNED_SHORT,0)
This works fine, now lets say I want to draw the second triangle (using indexes 3,4,5), I would need to do this
GL11.glDrawElements(GL11.GL_TRIANGLES,3,GL11.GL_UNSIGNED_SHORT,6)
Note even though I wanted the 3rd element I had to put a 6 here because everyone of the 3 elements is a short which is 2 bytes long.