glIndexPointer & glDrawArrays

Instead of using vertex arrays, I’m using vertex buffers to specify the data for glDrawArrays.

I am using 3 buffers of the same size. I am updating the buffers from a framebuffer object by glReadPixels. The framebuffer object has 3 textures attached of size width*height in RGBA format and type GL_FLOAT.

According to the following code, the index_buffer should dictate in what sequence the points from the vertex_buffer are drawn. But instead the problem is that the points are drawn in a sequential manner from the vertex buffer.

glBindBufferARB(GL_ARRAY_BUFFER, color_buffer);
glColorPointer(4, GL_FLOAT, 0, 0);

glBindBufferARB(GL_ARRAY_BUFFER, index_buffer);
glIndexPointer(GL_FLOAT, 4, 0);

glBindBufferARB(GL_ARRAY_BUFFER, vertex_buffer);
glVertexPointer(4, GL_FLOAT, 0, 0);

glDrawArrays(GL_POINTS, 0, width*height);

You may want to try out glDrawElements instead of glDrawArrays :wink:

Index array is something completely different (it is about color index).

What you are looking for is glDrawRangedElements in combination with a GL_ELEMENT_ARRAY_BUFFER

thanks for the quick reply.
I had one more query. Since I have my index buffer of float values, it will not work with glDrawRangedElements as it does not take float for indices ?
and is there a way to specify the stride for the indices (i.e. read the index after “stride” number of bytes/elements) ?

No, you will have to use tightly packed integers.