0

我已经实现了一个网格。线框渲染(三角形)没问题,但现在我想应用平面着色渲染,我得到的是一个没有体积的纯白色图形。

这是我使用的:

for(int i=0; i<mesh->nt; i++) {
    glShadeModel(GL_FLAT);
    glBegin(GL_TRIANGLES);


    int i0 = mesh->triangles[i].vInds[0];
    int i1 = mesh->triangles[i].vInds[1];
    int i2 = mesh->triangles[i].vInds[2];

    Vector n1 = GetNormal(mesh->vertices[i0], mesh->vertices[i1], mesh-                  >vertices[i2]);

    glNormal3dv((double *)&n1);

    glVertex3dv((double *)&mesh->vertices[i0]);
    glVertex3dv((double *)&mesh->vertices[i1]);
    glVertex3dv((double *)&mesh->vertices[i2]);

    glEnd();
}   

我计算了三角形的法线,但没有任何效果。任何想法?

4

2 回答 2

6

如果您没有启用灯光/照明,三角形将不会被着色。就那么简单。

于 2013-04-10T13:38:49.600 回答
1

也许这样更好?

glEnable(GL_LIGHTING);
glShadeModel(GL_FLAT);
glBegin(GL_TRIANGLES); // <-- start triangles before the loop, much faster

for(int i=0; i<mesh->nt; i++) 
{
    int i0 = mesh->triangles[i].vInds[0];
    int i1 = mesh->triangles[i].vInds[1];
    int i2 = mesh->triangles[i].vInds[2];

    Vector n1 = GetNormal(mesh->vertices[i0], 
                          mesh->vertices[i1], 
                          mesh->vertices[i2]);

    glNormal3dv((double *)&n1);

    glVertex3dv((double *)&mesh->vertices[i0]);
    glVertex3dv((double *)&mesh->vertices[i1]);
    glVertex3dv((double *)&mesh->vertices[i2]);
}   
glEnd();  
于 2013-04-10T14:35:38.547 回答