Jump to content
  • Advertisement
Sign in to follow this  
segmentation fault

VBO and Index

This topic is 3207 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!