Can indexed primitives be used when using vertex buffer objects in OpenGL ES 1.x?

I have an array that contains a list of vertices that I am copying to the GPU using a vertex buffer object. However, the vertex coordinates are meaningless on their own, since I also have an integer array containing a list of indices into a vertex array.

In this case, you can create another buffer object to store the indices, and then in the render function, concatenate the vertex array and the indices array to draw:

//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 read the api and the following confused me:
"While a non-null buffer object is bound to the GL_ELEMENT_ARRAY_BUFFER target, the glDrawElements index parameter, which is traditionally interpreted as a pointer to client memory, is instead interpreted as an offset in the buffer object, measured in base machine units" ...

I'm new to graphical programming, so I apologize if it doesn't make sense.

+1


source to share


1 answer


Yes it is possible. The official guide should help you. They recommend not to use unsigned bytes, stick to 16 or 32 bit indices for speed.



+2


source







All Articles