VBO with some mysterious garbage (windows 10)

I’ve got PARTIAL garbage geometry in my draw code when using vbo’s but not when using begin/end.
More simply, begin end works perfect, the vbo is mixed with trash, so I feel confident the data is good, but I’m missing something about the VBO. The VBO draws fine except for around face 5500 and later, which is (partially)corrupted (even when I dump the float to text, but not a problem if I draw with begin/end). I’ve tried different graphics cards/chips(AMD&Intel), so it is unlikely a specific graphics hardware issue/failure. (maybe the heap? but begin/end works fine with the same arrays so unlikely) I think its got something to do with the array(word size off the array or something?), but not the elements in the array. Again,Begin/End works fine.

//the good code
GLvoid renderTri(ACTOR *someActor)
  for (int f=0; f < someActor->FaceCnt;f++)
    int vertai=someActor->faceIDarr[(f*3)+0];//face vert index a
    int vertbi=someActor->faceIDarr[(f*3)+1];//face vert index b
    int vertci=someActor->faceIDarr[(f*3)+2];//face vert index c
//no worky good
GLvoid renderVBO(ACTOR *someActor)
  glEnableClientState(GL_VERTEX_ARRAY);             // activate vertex position array
  glEnableClientState(GL_NORMAL_ARRAY);             // activate vertex normal array
  glEnableClientState(GL_TEXTURE_COORD_ARRAY);      // activate texture coord array
  if (builtVBO==0)  //befor first draw create the vbos
  glGenBuffers(1, &someActor->xyzID);
  glBindBuffer(GL_ARRAY_BUFFER, someActor->xyzID);
  glBufferData(GL_ARRAY_BUFFER, 3*sizeof(GLfloat)*someActor->VertCnt, 0,GL_STATIC_DRAW);
  glBufferSubData(GL_ARRAY_BUFFER, 0, 3*sizeof(GLfloat)*someActor->VertCnt, someActor->xyzverts);
  glBindBuffer(GL_ARRAY_BUFFER, 0);
  glGenBuffers(1, &someActor->xyznID);
  glBindBuffer(GL_ARRAY_BUFFER, someActor->xyznID);
  glBufferData(GL_ARRAY_BUFFER, 3*sizeof(GLfloat)*someActor->VertCnt, 0,GL_STATIC_DRAW);
  glBufferSubData(GL_ARRAY_BUFFER, 0, 3*sizeof(GLfloat)*someActor->VertCnt, someActor->xyznorms);
  glBindBuffer(GL_ARRAY_BUFFER, 0);
  glGenBuffers(1, &someActor->uvID);
  glBindBuffer(GL_ARRAY_BUFFER, someActor->uvID);
  glBufferData(GL_ARRAY_BUFFER, 2*sizeof(GLfloat)*someActor->VertCnt, 0,GL_STATIC_DRAW);
  glBufferSubData(GL_ARRAY_BUFFER, 0, 2*sizeof(GLfloat)*someActor->VertCnt, someActor->uvcoords);
  glBindBuffer(GL_ARRAY_BUFFER, 0);
  glGenBuffers(1, &someActor->faceID);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, someActor->faceID);
  glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint)*someActor->FaceCnt*3, someActor->faceIDarr, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, someActor->xyzID);
glVertexPointer(3, GL_FLOAT, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, someActor->xyznID);
glNormalPointer(GL_FLOAT, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, someActor->uvID);
glTexCoordPointer(2, GL_FLOAT, 0, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, someActor->faceID);
glDrawElements(GL_TRIANGLES, someActor->FaceCnt*3, GL_UNSIGNED_INT, 0);//BUFFER_OFFSET(0)); 


In my admittedly far-from-expert experience with OpenGL, bad geometry with VBOs is more often due to the GPU interpreting the data in a way you didn’t intend than from memory corruption. Usually, though, you would see that consistently as opposed to only after a few thousand triangles.

My #1 recommendation for this situation is an open source application called RenderDoc. This will let you capture a frame of your program and see every single draw command, every bit of data being sent to the GPU, and the whole pipeline state; it has made the entire process of troubleshooting my OpenGL code 1000% easier.

Also, a possible workaround to consider - I have personally had better luck with vertex arrays (VAOs) than VBOs, but depending on the version of OpenGL you’re working with it they not be supported. The wiki says 3.0, and the caveat is that going to modern OpenGL will mean that your code using the immediate mode commands (glVertex3f, glNormal3f, etc) won’t be supported anymore. In a VAO you can interleave all the data in a single array buffer - I strongly recommend writing some code that will automatically calculate the offsets for your vertex attributes, makes it much easier to keep track of once you start packing more data in.

I think I found my answer, which can be summed up in this post

In a weird twist of fate 2.1 is orphaned, with 1.5 (apparently) still natively supported by windows. Most libraries having trouble with anything before 3.0. I have to give some serious reflection and evaluation on continuing with OpenGL, but I think we all know the answer.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.