背面剔除线路环 [英] Back Face Culling for Line Loop

查看:95
本文介绍了背面剔除线路环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用z缓冲区渲染3D三角形网格.但是,当我将模型渲染为线框网格时,我还看到了应该被正面隐藏的三角形面.因此,我使用了背面剔除方法,如下所示:

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

drawWireFrame函数如下:

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.

谢谢.

推荐答案

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

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.

如果要绘制此类图元的线框图,则可以将其直接绘制为三角形(或其他类型),并设置glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)以获得线框可视化.在这种情况下,背面剔除将具有所需的效果.另外请注意,设置glPolygonMode就足够了,因此对于线框和实体渲染,您不需要其他绘制方法.

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.

这篇关于背面剔除线路环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆