from indices to vertexbuffers

Started by
4 comments, last by Limitz 17 years, 8 months ago
Hi, I want to do the following, but i don't really know how to do it, i guess i am looking for a method to add an offset to indices to vertices. This is what i want to do: I have an indexed triangle strip, i want to store it on the GPU. I have several vertex buffers i want to store at the GPU. Now i want to make the GPU draw the triangle strip using one of the vertex buffers as the base of its indices. Anyone know a nice way to do this? Greetings...
Advertisement

I am not sure if I understand exactly your problem.

You seem to be familiar with VBs and IBs so what seems to be the problem with using them ?

DX Sdk comes with simple examples of

Setting Vertex Buffer
Setting Index Buffer
Setting the vertex declaration

... plenty of stuff before reaching the point of actually drawing something ...

DrawIndexedPrimitive
Well the problem is that i want to store them on the GPU. I know howto declare them in user memory and draw both the VB en IB in one call, but i want to store a vertex buffer on the GPU that contains several concatenated vertex buffers. Now i want to store the index buffer on the gpu, set an offset for the vertex buffer and draw the resulting set.

It's like this. I have terrain data 257 * 257 vertices. and a 17 by 17 trianglestrip. I want to set the offset for the teraindata to 17*17 to get the second block for instance, and then draw the trianglestrip which uses indices 0 to 17*17-1, so it uses the same indices + offset to draw a different portion of the terrain.

I am using opengl btw...
you have to perform the offset, in bytes, in the gl*Pointer() calls
Quote:Original post by Limitz
Well the problem is that i want to store them on the GPU. I know howto declare them in user memory and draw both the VB en IB in one call, but i want to store a vertex buffer on the GPU that contains several concatenated vertex buffers. Now i want to store the index buffer on the gpu, set an offset for the vertex buffer and draw the resulting set.

It's like this. I have terrain data 257 * 257 vertices. and a 17 by 17 trianglestrip. I want to set the offset for the teraindata to 17*17 to get the second block for instance, and then draw the trianglestrip which uses indices 0 to 17*17-1, so it uses the same indices + offset to draw a different portion of the terrain.

I am using opengl btw...

I also don't clearly understand the problem ... let me see:

1) Of course you can store the index buffer on the GPU, just use GL_ELEMENT_ARRAY_BUFFER with the buffer target (instead of GL_ARRAY_BUFFER with the data buffers).

2) Just provide an incremented pointer to glDrawElements to start from an offset on the data buffer. Like for the second strip, this should work:
glDrawElements(GL_TRIANGLE_STRIP, 17*17, GL_UNSIGNED_SHORT, BUFFER_OFFSET(17*17*sizeof(vertex)));

/edit: After re-reading phantom's post, seems like I misunderstood; you have just one set of indices (for one strip). Sorry about the confusion, as he said use gl*Pointer().
Quote:Original post by phantom
you have to perform the offset, in bytes, in the gl*Pointer() calls


Thanks a lot. I'll try that :)

This topic is closed to new replies.

Advertisement