I have an array that contains a list of vertices which I copy to the GPU using a vertex buffer object. However the vertex coordinates on their own are meaningless as I also have an integer array that contains a list of indices into the vertex array.
In this scenario is it possible to create another buffer object to store the indices and then in the render function bind both the vertex array and indices array for drawing:
//vertex coordinates glBindBuffer(GL_ARRAY_BUFFER, bufferId1); //index coordinates glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferId2); glVertexPointer(3, GL_FLOAT, 0, 0); //Not sure if this should be Unsigned BYTE or Unsigned SHORT glDrawElements(GL_POINTS, 6, GL_UNSIGNED_BYTE, 0);
I have read the api and the following confused me:
‘While a non-zero buffer object is bound to the GL_ELEMENT_ARRAY_BUFFER target, the indices parameter of glDrawElements that is traditionally interpreted as a pointer to client-side memory is instead interpreted as an offset within the buffer object measured in basic machine units.’
I am pretty new to graphics programming so apologize if any of this does not make sense.
Yes, this is possible. The official tutorial should help you along. They recommend against using unsigned byte, stick with 16 or 32 bit indexes for speed.