OBJ模型渲染差距

时间:2012-10-11 03:29:11

标签: c++ opengl 3d wavefront

当我渲染我使用自己构建的解析器解析的OBJ Wavefront模型时,我在渲染时得到以下结果:

enter image description here

是否存在正常的间隙,或者它只是来自错误的渲染代码?

以下是渲染代码:

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();

1 个答案:

答案 0 :(得分:0)

您是否检查过您的模型是使用三角形而非四边形创建的?您找到的大多数模型默认会以四边形渲染,因此您可以将其加载到3D程序(如Blender或Maya)中并将网格转换为三角形(Blender中的Ctrl + T),或更改解析器以处理四边形。