-1

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

在此处输入图像描述

存在的差距是正常的还是仅仅是由于错误的渲染代码造成的?

这是渲染代码:

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

1 回答 1

0

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

于 2013-10-11T02:44:12.020 回答