[LWJGL] VBO and glDrawRangeElements (SOLVED)

Hi,

I have a bit difficulty to use glDrawRangeElements with VBO in LWJGL so I want to double check the use of :

GL12.glDrawRangeElements(int mode, int start, int end, int indices_count, int type, long indices_buffer_offset)

I have created a VBO with several 3d model in it. I have checked the data that I parse to the GPU and they seems to be correct. When I draw the 1srt object, I have no problem. But when I want to draw the others, it is messed up. I think I have miss understand the meaning of the parameters of glDrawRangeElements :


ref.start = number of the first index
ref.size = number of index need to draw the model
GL12.glDrawRangeElements(GL11.GL_TRIANGLES ,
                                      ref.start,
                                      ref.start+ref.size,
                                      ref.size,
                                      GL11.GL_SHORT,
                                      0)

A quick search seems to indicate that this is quite a common problem, the meaning of the parameters is not obvious (frankly it bamboozled me!) and I’ve never used this method or seen any tutorials/examples/demos that use it.

From what I’ve read it looks to me like the version you were trying to use is really aimed at vertex arrays anyway rather than VBOs per se (it was introduced into the 1.2 API), the parameters are odd because the OpenGL is attempting to optimise fetches of indices from memory to the GPU - not an issue if you’re using VBOs and not vertex arrays.

Might have got the wrong end of the stick but that’s what it looks like to me - any wiser souls know better?

As you’re using LWJGL so can I suggest using one of the glDrawRangeElements(mode, start, end, index-buffer) methods which (if I understand what you’re trying to achieve) will do what you want.

  • stride

Thanks for the reply.

The problem with GL12.glDrawRangeElements(mode, start, end, index-buffer) is that it send the index buffer each time you call it. While GL12.glDrawRangeElements(int mode, int start, int end, int indices_count, int type, long indices_buffer_offset), the index buffer is send only once (at the loading of the models).

[quote=“Bonbon-Chan,post:3,topic:40979”]
Assuming you are using a index buffer (as opposed to a vertex array) for your indices they will only be uploaded once when you call glBufferData(), that’s the whole point of VBOs - or am I missing the point?

I can confirm this. Now to work around the 90% quote limitation…

Please read the spec very carefully:
http://www.opengl.org/sdk/docs/man/xhtml/glDrawRangeElements.xml

You’re doing it wrong :slight_smile:

The parameters start and end contain the min and max values in the indices array.

Darmn…
min = min of the whole indexes != min of the model indexes…
max = max of the whole indexes != max of the model indexes…


GL12.glDrawRangeElements(GL11.GL_TRIANGLES ,
                                      0,
                                      nbTotalVertex-1,
                                      ref.size,
                                      GL11.GL_UNSIGNED_SHORT,
                                      ref.start * 2) // * 2 since it is GL_UNSIGNED_SHORT

It work better now :smiley: thanks