在 OpenGL 中启用深度测试后,我的整个屏幕一片空白(恢复为清晰的颜色) - 为什么?
在我使用 OpenGL 和 GLUT 的 C++ 图形应用程序中,我想通过以下方式启用深度测试。
glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
但是,这两行代码清除了我的屏幕,现在只是清晰的颜色。我想知道为什么。
我应该有一些原始的实心球体和立方体。
In my C++ graphics application using OpenGL and GLUT, I want to enable depth testing via
glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
However, these two lines of code clear my screen, which is now just the clear color. I was wondering why.
I am just supposed to have a few primitive solid spheres and cubes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您好像忘记清除深度缓冲区,因此由于深度缓冲区内存中存在任何预先存在的垃圾而导致深度测试失败。尝试将 GL_DEPTH_BUFFER_BIT 添加到您的 glClear() 调用中,如下所示:
祝您好运!
Sounds like you've forgotten to clear the depth buffer and are thus failing the depth test due to whatever preexisting garbage is in the depth buffer memory. Try to add GL_DEPTH_BUFFER_BIT to your glClear() call, like so:
Good luck!
确保启用深度测试后还在 Z 近值和 Z 远值之间进行绘制。
Make sure you're also drawing between your Z near and Z far values after enabling depth testing.