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)
{
   glBegin(GL_TRIANGLES);
  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
    glMultiTexCoord2f(GL_TEXTURE0,someActor->uvcoords[(vertai*2)+0],someActor->uvcoords[(vertai*2)+1]);
    glNormal3f(someActor->xyznorms[(vertai*3)+0],someActor->xyznorms[(vertai*3)+1],someActor->xyznorms[(vertai*3)+2]);
    glVertex3f(someActor->xyzverts[(vertai*3)+0],someActor->xyzverts[(vertai*3)+1],someActor->xyzverts[(vertai*3)+2]);
    glMultiTexCoord2f(GL_TEXTURE0,someActor->uvcoords[(vertbi*2)+0],someActor->uvcoords[(vertbi*2)+1]);
    glNormal3f(someActor->xyznorms[(vertbi*3)+0],someActor->xyznorms[(vertbi*3)+1],someActor->xyznorms[(vertbi*3)+2]);
    glVertex3f(someActor->xyzverts[(vertbi*3)+0],someActor->xyzverts[(vertbi*3)+1],someActor->xyzverts[(vertbi*3)+2]);
    glMultiTexCoord2f(GL_TEXTURE0,someActor->uvcoords[(vertci*2)+0],someActor->uvcoords[(vertci*2)+1]);
    glNormal3f(someActor->xyznorms[(vertci*3)+0],someActor->xyznorms[(vertci*3)+1],someActor->xyznorms[(vertci*3)+2]);
    glVertex3f(someActor->xyzverts[(vertci*3)+0],someActor->xyzverts[(vertci*3)+1],someActor->xyzverts[(vertci*3)+2]);
 }
 glEnd();
}
//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
  {
  builtVBO+=1;
  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, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, someActor->faceID);
glDrawElements(GL_TRIANGLES, someActor->FaceCnt*3, GL_UNSIGNED_INT, 0);//BUFFER_OFFSET(0)); 
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}

Capture

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
https://answers.microsoft.com/en-us/windows/forum/windows_10-update-winpc/opengl-problem-in-windows-10/aff41ab9-0b6f-4317-8dcb-67ba861584c5

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.