Opengl深度测试

void RenderScene(void)
{
    // 设置正面为填充模式
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
    glRotatef(xRot, 1.0f, 0.0f, 0.0f);
    glRotatef(yRot, 0.0f, 1.0f, 0.0f);
    glPolygonMode(GL_FRONT, GL_FILL); 
    // 设置反面为线形模式
    glPolygonMode(GL_BACK, GL_FILL); 
    glEnable(GL_DEPTH_TEST); // 1), Open the depth test 
    glDepthFunc(GL_LESS); //the default is GL_LESS, the less is front

    // 设置逆时针绘制一个正方形
#define Zorder -0.3f //2)the z orde that the depth
#if 0
    glEnable(GL_CULL_FACE);
    glCullFace(GL_FRONT_AND_BACK);
    glColor3f(1.0f, 0.0f, 0.0f);
    glBegin(GL_POLYGON);              
    glVertex2f(-0.5f, -0.5f);
    glVertex2f(0.0f, -0.5f);
    glVertex2f(0.0f, 0.0f);
    glVertex2f(-0.5f, 0.0f);
    glEnd();
    glDisable(GL_CULL_FACE);
#else
    glColor3f(1.0f, 0.0f, 0.0f);
    glBegin(GL_POLYGON);              
    glVertex3f(-0.5f, -0.5f, Zorder);
    glVertex3f(0.0f, -0.5f, Zorder);
    glVertex3f(0.0f, 0.0f, Zorder);
    glVertex3f(-0.5f, 0.0f, Zorder);
    glEnd();
#endif
    // 设置顺时针绘制一个正方形
    
    glColor3f(0.0f, 0.0f, 1.0f);
    glBegin(GL_POLYGON);             
    //glVertex2f(0.0f, 0.0f);
    //glVertex2f(0.0f, 0.5f);
    //glVertex2f(0.5f, 0.5f);
    //glVertex2f(0.5f, 0.0f);
    glVertex3f(-0.3f, -0.3f, -Zorder);
    glVertex3f(0.2f, -0.3f, -Zorder);
    glVertex3f(0.2f, 0.2f, -Zorder);
    glVertex3f(-0.3f, 0.2f, -Zorder);
    glEnd();

    // Flush drawing commands
    glutSwapBuffers();
    glPopMatrix();
    glDisable(GL_DEPTH_TEST); // 3),close the depth 
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值