View Full Version : VBO problem, different in 2 applications

10-03-2011, 06:22 AM
Hello Guys,
I am having a very strange problem with the vertexbuffers. I am extracting data from a 3d model format to my own format - which currently worked for all tested models except one. This one model consists of 1x Vertexbuffer, 1x Texturecoordsbuffer, 1x Normalsbuffer, 1x Indicesbuffer and 7x different objects which each call glDrawElements with different parameters. (So they are drawing different parts of the ONE vertexbuffer, normalsbuffer, ...)

I am using exactly the same draw and initialization code like in the original application, yet there are parts of the original application that are closed source (a library) so there might be some opengl settings done that I don't see.

The drawing works for 5 of those 7 different objects, but not for the last two ones.


At the pictures at the top it looks like just the uv-coordinates are wrong - which is not true. If I break it down into those "different objects" and only draw object number 6, then it looks like the pictures in the middle, if I draw only number 7 it looks like the pictures in the bottom. As you can see the problem is that different vertices(or indices?) are drawn, even though the buffers are the same and the parameters for glDrawElements are the same. (The "different objects" are the faces that are using the same texture, aka Materialfaces)

I am 99.9% sure that both applications are using the same vertices, texturecoords, normals, indices of unsigned int* / float* arrays for the VBO initialization. I checked them several times in several places of the code.

Here is the code:
Initialization for vertexes, normals, texturecoords:

glGenBuffers(1, &m_vboindex);
glBindBuffer(GL_ARRAY_BUFFER, m_vboindex);
glBufferData(GL_ARRAY_BUFFER, vboparam, values, GL_STATIC_DRAW);

Initialization for indices:

glGenBuffers(1, &m_vboindex);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_vboindex);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, vboparam, values, GL_STATIC_DRAW);

Draw code

// Push OpenGL attributes.

// Begin Draw //
// Set vertex position array.
glBindBuffer(GL_ARRAY_BUFFER, m_vertexbuffer);
glVertexPointer(m_vertexbuffer_stride, GL_FLOAT, 0, 0);

// Set normal array.
if (m_normalsbuffer_set)
glBindBuffer(GL_ARRAY_BUFFER, m_normalsbuffer);
glNormalPointer(GL_FLOAT, 0, 0);

// Set UV array.
if (m_texcoordsbuffer_set)
glBindBuffer(GL_ARRAY_BUFFER, m_texcoordsbuffer);
glTexCoordPointer(m_texcoordsbuffer_stride, GL_FLOAT, 0, 0);

// Set index array.
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indicesbuffer);

// Draw all material faces
for (unsigned int i = 0; i < m_materialfaces.size(); i++)
//if (i==5) <- enable to produce the pictures in the middle (see link above)

// Reset VBO binding.
glBindBuffer(GL_ARRAY_BUFFER, 0);

Code for materialfaces.at(i)->Draw

// Use textures etc. [...]

// Draw materialfaces
glDrawElements(GL_TRIANGLES, m_elementcount, GL_UNSIGNED_INT, reinterpret_cast<const GLvoid *>(m_offset));

I am also 100% sure that m_offset and m_elementcount are the same for each object in each of the applications.

Further I also tried to not use the glDrawElements funciton with the last parameter as offset but as part of the indices array - I got exactly the same result, so I am pretty sure that the indices array is not the problem.

So in short words:
Same code, same buffers, almost all models do work, one part of one model doesn't.

Is there maybe a chance that when passing the float* vertices to the Vertexbuffer that it changes the order of it if some thing happens? Or maybe a initialization call that I forgot? Or some special internal behaviour of the VBOs that I didn't kept in mind?

Thanks in advance,

carsten neumann
10-03-2011, 03:36 PM
You could try running the reference program and your own code through glIntercept, bugle, or apitrace (or a similar tool) to record all the OpenGL calls that are made and compare the resulting logs to find the difference.