• Advertisement
Sign in to follow this  

VBOs: what am doing wrong?

This topic is 2222 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

This is the code I wrote for drawing using vbos:


VBOS:
[code]
GLuint VertexVBO = 0;

glGenBuffers(1, &VertexVBO);

glBindBuffer(GL_ARRAY_BUFFER, VertexVBO);
glBufferData(GL_ARRAY_BUFFER, mesh.numtriangles * 3 * sizeof(float), mesh.vertices, GL_STATIC_DRAW);

glEnableClientState(GL_VERTEX_ARRAY);

glBindBuffer(GL_ARRAY_BUFFER, VertexVBO);
glVertexPointer(3, GL_FLOAT, 0, 0);

glDrawArrays(GL_TRIANGLES, 0, mesh.numtriangles*3);

glDisableClientState(GL_VERTEX_ARRAY);

glDeleteBuffers(1, &VertexVBO);[/code]


when I run this nothing gets drawn but if I do it like this for plain vertex arrays it works fine (albeit slower):


Vertex Arrays:

[code]
glEnableClientState(GL_VERTEX_ARRAY);

glVertexPointer(3, GL_FLOAT, 0, mesh.vertices );

glDrawArrays(GL_TRIANGLES, 0, mesh.numtriangles*3);

glDisableClientState(GL_VERTEX_ARRAY);[/code]

What did I do wrong when trying to implement VBOS?

Share this post


Link to post
Share on other sites
Advertisement
I suspect that the problem might be that you're deleting the buffer diectly after telling GL to draw something. There's no way of knowing when the actual rendering happens, depending on your platform and gl driver (maybe the driver is just building a list of GOU commands that are executed during a flush or a call to SwapBuffers()).

Try creating the array at startup, and the delete it during the application shutdown.

Share this post


Link to post
Share on other sites
mesh.numtriangles * 3 * sizeof(float) looks wrong for the size of your VBO. Each triangle has 3 vertices, and each vertex has 3 floats, so that should be * 9 instead. Your hardware and/or driver is likely recognising that your VBO isn't big enough for your draw call params and failing gracefully by drawing nothing (personally I'd prefer a big dirty crash - at least you get some indication of what you've done wrong that way).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement