Sign in to follow this  
segmentation fault

VBO and Index

Recommended Posts

Hi everyone. I have a very basic question about using index to render the content of a VBO. You have to create a vbo for your vertex data and another (or many others) for indexes. I'm doing something like this right now to fill the vertex vbo : // Generates an id for the vertex and index vbos. glGenBuffers(1, &m_VertexVBO); glGenBuffers(1, &m_IndexVBO1); glBindBuffer(GL_ARRAY_BUFFER, m_VertexVBO); // Allocate the internal data store without copying the data // and copy the vertices. glBufferData(GL_ARRAY_BUFFER, nbVertex*sizeof(struct VertexAttribs), &vertexArray[0], GL_STATIC_DRAW); glVertexPointer(3, GL_FLOAT, sizeof(struct attrib), BUFFER_OFFSET(0)); glColorPointer(3, GL_FLOAT, sizeof(struct attrib), BUFFER_OFFSET(12)); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_IndexVBO1); glBufferData(GL_ELEMENT_ARRAY_BUFFER, 21*sizeof(unsigned short), &FullIndex[0], GL_STATIC_DRAW); Then, to render the content of the vbo, i just call : glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glDrawElements(GL_TRIANGLE_STRIP, 21, GL_UNSIGNED_SHORT, BUFFER_OFFSET(0)); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); This code works fine. But, if i had two (or more) vertex VBOs with multiple index VBOs, how do i select the vertex VBO i want to render using glDrawElements ? I did bind the vertex vbo to fill it then i bound the index vbo. But what if i want to render the content of another vertex vbo ? In other words, how do i tell wich vertex vbo my index vbo will work on ?

Share this post


Link to post
Share on other sites
You have to bind your VBO and indexbuffer before calling glDrawElements.
So you want to do something like :

glBindBuffer(GL_ARRAY_BUFFER, m_VertexVBO);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(VertexAttribs), BUFFER_OFFSET(0));
glColorPointer(3, GL_FLOAT, sizeof(VertexAttribs), BUFFER_OFFSET(12));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_IndexVBO);
glDrawElements(GL_TRIANGLE_STRIP, 21, GL_UNSIGNED_SHORT, 0);


Share this post


Link to post
Share on other sites
Quote:
Original post by Arkhyl
You have to bind your VBO and indexbuffer before calling glDrawElements.
So you want to do something like :
*** Source Snippet Removed ***



So you just bind the two vbos (the geometry and the index) you want to use.
Thank you very much for the answer.

Bonne journée :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this