PDA

View Full Version : VBOs



felpy
07-22-2009, 02:50 PM
Is there anything wrong in the way I try to draw VBOs/IBOs? I only manage to get random lines on the screen that appear and disappear every other frame.

Here is the code to create them:
// VBO
glGenBuffers(1, &VBOID);
glBindBuffer(GL_ARRAY_BUFFER, VBOID);
glBufferData(GL_ARRAY_BUFFER, VBOSize*sizeof(float), NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, VBOSize*sizeof(GLushort), VBO);
glBindBuffer(GL_ARRAY_BUFFER, 0);

glGenBuffers(1, &IBOID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBOID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, IBOSize*sizeof(GLuint), NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, IBOSize*sizeof(GLushort), IBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
// end VBO

And here the way I draw them:

// Draw VBO
glEnableClientState(GL_VERTEX_ARRAY); // enable array states
glBindBuffer(GL_ARRAY_BUFFER, VBOID); // binding the VBO and assign NULL to the vertex pointer
glVertexPointer(3, GL_FLOAT, 0, NULL);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBOID); // binding the VBO and assign NULL to the vertex pointer
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, NULL); // draw elements in the IBO

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); // debind IBO
glBindBuffer(GL_ARRAY_BUFFER, 0); // debind VBO
glDisableClientState(GL_VERTEX_ARRAY); // disable array states
//

Here is the complete source:
http://pastebin.com/f12db0631

plasmonster
07-22-2009, 04:43 PM
When in doubt, ferret it out:
http://www.songho.ca/opengl/gl_vbo.html

Probably best to start with a tried and true recipe where possible, then season to taste.

Hope it helps.