Strange mesh import problem with Assimp and OpenGL
Posted
by
Morgan
on Game Development
See other posts from Game Development
or by Morgan
Published on 2012-06-23T21:06:42Z
Indexed on
2012/06/23
21:25 UTC
Read the original article
Hit count: 367
Using the assimp library for importing 3D data into an OpenGL application. I get some strange problems regarding indexing of the vertices:
If I use the following code for importing vertex indices:
for (unsigned int t = 0; t < mesh->mNumFaces; ++t)
{
const struct aiFace * face = &mesh->mFaces[t];
if (face->mNumIndices == 3)
{
indices->push_back(face->mIndices[0]);
indices->push_back(face->mIndices[1]);
indices->push_back(face->mIndices[2]);
}
}
I get the following result:
Instead, if I use the following code:
for(int k = 0; k < 2 ; k++)
{
for (unsigned int t = 0; t < mesh->mNumFaces; ++t)
{
const struct aiFace * face = &mesh->mFaces[t];
if (face->mNumIndices == 3)
{
indices->push_back(face->mIndices[0]);
indices->push_back(face->mIndices[1]);
indices->push_back(face->mIndices[2]);
}
}
}
I get the correct result:
Hence adding the indices twice, renders the correct result?
The OpenGL buffer is populated, like so:
glBufferData(GL_ELEMENT_ARRAY_BUFFER,
indices->size() * sizeof(unsigned int),
indices->data(),
GL_STATIC_DRAW);
And rendered as follows:
glDrawElements(GL_TRIANGLES,
vertexCount*3,
GL_UNSIGNED_INT,
indices->data());
© Game Development or respective owner