Pergunta

When I render a OBJ Wavefront model which I parse using a parser that I built myself, I get the following result when rendering:

enter image description here

Are the gaps that are present normal or is it just from faulty rendering code?

Here is the rendering code:

glPushMatrix();
glColor3f(1.0f, 1.0f, 1.0f);
glScaled(scale, scale, scale);

glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

for (int i = 0; i < vertices_indexes.size()-3; i+=3) {
    glBegin(GL_TRIANGLE_FAN);
        if (is_normals) glNormal3f(normals.at(normals_indexes[i]).x, normals.at(normals_indexes[i]).y, normals.at(normals_indexes[i]).z);
        glVertex3f(vertices.at(vertices_indexes[i]).x, vertices.at(vertices_indexes[i]).y, vertices.at(vertices_indexes[i]).z);

        if (is_normals) glNormal3f(normals.at(normals_indexes[i+1]).x, normals.at(normals_indexes[i+1]).y, normals.at(normals_indexes[i+1]).z);
        glVertex3f(vertices.at(vertices_indexes[i + 1]).x, vertices.at(vertices_indexes[i + 1]).y, vertices.at(vertices_indexes[i + 1]).z);

        if (is_normals) glNormal3f(normals.at(normals_indexes[i+2]).x, normals.at(normals_indexes[i+2]).y, normals.at(normals_indexes[i+2]).z);
        glVertex3f(vertices.at(vertices_indexes[i + 2]).x, vertices.at(vertices_indexes[i + 2]).y, vertices.at(vertices_indexes[i + 2]).z);
    glEnd();
}

glPopMatrix();
Foi útil?

Solução

Have you checked that your model is created with triangles and not quads? Most models you find will come rendered in quads by default, so you can either load it up in a 3D program (like Blender or Maya) and convert the mesh to triangles (Ctrl+T in Blender), or change your parser to handle quads.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top