Jump to content
  • Advertisement
Sign in to follow this  
sjaakiejj

OpenGL Vertex buffer Objects: Strange glBufferData behaviour

This topic is 2498 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 guys,

I've been working on modifying my application to use Vertex Buffer Objects, but I encountered a strange problem that I have been stuck with for days (which is probably related to the way I implemented it).

VBOs are rendered only if I actually pass the buffer data, using glBufferData, in the display function, just before calling glDrawArrays. If I pass the data to glBufferData beforehand (in the init functions) and simply remember the VBO reference, it seems that the data is somehow forgotten.

The relevant pieces of code can be found below. The object is rendered if I #define RENDER_BUFFER, and otherwise it's not. I checked for glErrors on every OpenGL call, but none were present.



[source]void Init(){
#ifndef RENDER_BUFFER
glGenBuffers(1, &mVboObject);
glBindBuffer(GL_ARRAY_BUFFER, mVboObject);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * mNumFaces * 3 , mVertices.get(), GL_STATIC_DRAW);
#else
glGenBuffers(1, &mVboObject);
#endif
}[/source]

[source]void Render(){
/*
* Draw the object
*/

glEnableClientState(GL_VERTEX_ARRAY);


#ifdef RENDER_BUFFER
//This renders perfectly
glBindBuffer(GL_ARRAY_BUFFER, mVboObject);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * mNumFaces * 3 , mVertices.get(), GL_STATIC_DRAW);

#else
//This doesn't render at all
glBindBuffer(GL_ARRAY_BUFFER, mVboObject);

#endif

glVertexPointer(3,GL_FLOAT,sizeof(Vertex),0);

glPushMatrix();
glScaled(20,20,20);
glDrawArrays(GL_TRIANGLES, 0, mNumFaces*3);
glPopMatrix();

glDisableClientState(GL_VERTEX_ARRAY);

glBindBuffer(GL_ARRAY_BUFFER, 0);
}[/source]

Thanks in advance for your time, and hopefully help.

Share this post


Link to post
Share on other sites
Advertisement
I definitely thought I did, but after your comment I went and checked to make sure and I somehow managed to start the main loop before actually initialising the object. In fact, I was creating the object twice, one time before and one time after the call to glutMainLoop and the GL Initialisation code.
So it looked like this:


MyObject* obj = new MyObject("File.obj"); //This shouldn't have been here at all
Graphics.init(); //The call to glutMainLoop was in here, which caused the problem
obj = new MyObject("File.obj"); //This wasn't called until the glutMainLoop terminated


Stupid mistake, but thanks for your help, saves me a long evening of debugging :D

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!