OpenGL中的深度缓冲区 [英] Depth Buffer in OpenGL

查看:88
本文介绍了OpenGL中的深度缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用OpenGL绘制一系列矩形,但是应该显示在矩形下方的一些矩形出现在其上方.

I am trying to draw a series of rectangles using OpenGL but some of the ones that should appear below a rectangle appear above it.

要启用我正在使用的深度功能

To enable the depth function I am using

glClearDepth(1.0f);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);

我在每次抽奖开始时都使用gluLookAt.这是问题的图像.蓝色矩形的y值比绿色矩形的y值高.

I am using gluLookAt at the begining of each draw. Here is an image of the problem. The blue rectangles are positioned with higher y values than the green rectangles.

如您在顶部图像中看到的,一些绿色矩形出现在蓝色矩形上方.知道为什么会发生这种情况以及如何解决该问题吗?可能与我绘制矩形的顺序有关吗?

As you can see in the top image some of the green rectangles appear above the blue ones. Any idea why this is happening and what I can do to fix it? Could it have something to do with the order that I'm drawing the rectangles?

推荐答案

清除颜色缓冲区时,还要清除深度缓冲区吗?

When you clear your colour buffer are you also clearing the depth buffer?

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

您确定图像不正确吗?实际上其中一些绿色方块
确实比蓝色的要高.

Are you sure the image isn't correct? Some of those green squares actually
do look higher than the blue ones.

这篇关于OpenGL中的深度缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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