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.
Lines don't have a front and a back face - lines don't have faces at all. Backface culling only works on primitive types which define faces, namely triangles (and traingle-bases primitives like strips and fans), and, for deprecated GL, also quad-based primtives and polygons.
If you want wireframe drawings of such primitives, you can directly draw them as triangles (or the other types) and set glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
to get wireframe visualization. In that case, backface culling will have the desired effect. Also note that setting glPolygonMode
is enough, so you don't need different drawing methods for wireframe and solid renderings.