2

I am using z-buffer to render my 3D triangular mesh. However, when I rendered the model as a wireframe mesh, I also saw the triangle faces which should have been hidden by the front face. So, I used the back face culling as follows:

            glEnable(GL_CULL_FACE);
            glCullFace(GL_BACK);
            drawWireFrame();
            glDisable(GL_CULL_FACE);

The drawWireFrame function is as follows:

void drawWireFrame()
{
    int i, j;
    glColor3d(1., 0., 0.);

    HE_edge *curr;

    for (int i = 0; i < he_f_count; i++)
    {
        glBegin(GL_LINE_LOOP);
        curr = m_HE_face[i].edge;
        glNormal3f(curr->prev->vert->vnx, curr->prev->vert->vny, curr->prev->vert->vnz);
        glVertex3f(curr->prev->vert->x, curr->prev->vert->y, curr->prev->vert->z);
        glNormal3f(curr->vert->vnx, curr->vert->vny, curr->vert->vnz);
        glVertex3f(curr->vert->x, curr->vert->y, curr->vert->z);
        glNormal3f(curr->next->vert->vnx, curr->next->vert->vny, curr->next->vert->vnz);
        glVertex3f(curr->next->vert->x, curr->next->vert->y, curr->next->vert->z);
        glEnd();
    }

}

However, I am still getting the same result I got before adding back face culling. Could you please help me identify what am I missing here.

Thank you.

4

1 回答 1

2

线条没有正面和背面 - 线条根本没有正面。背面剔除仅适用于定义面的基​​元类型,即三角形(以及带状和扇形等基于三角形的基元),并且对于已弃用的 GL,还适用于基于四边形的基元和多边形。

如果你想要这样的图元的线框图,你可以直接将它们画成三角形(或其他类型)并设置glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)以获得线框可视化。在这种情况下,背面剔除将产生所需的效果。还要注意设置glPolygonMode就足够了,所以线框和实体渲染不需要不同的绘制方法。

于 2015-11-14T16:35:39.553 回答