OpenGL 中奇怪的裁剪问题

发布于 2024-08-05 09:35:45 字数 159 浏览 4 评论 0原文

我对 OpenGL 非常陌生,所以请耐心等待。 :) 我正在学习 NeHe 的 OpenGL 教程,并且我已经开发了我自己的第 5 课版本,其中您将围绕原点旋转 3D 形状。我不确定我做错了什么,我几乎逐行复制了代码,但我在表面上看到了奇怪的重叠。

有谁对导致此类问题的原因有任何建议吗?

I am very very new to OpenGL, so please bear with me. :) I'm working through NeHe's OpenGL tutorials, and I have developed my own version of Lesson 5, in which you rotate a 3D shape around the origin. I'm not sure what I did wrong, I copied the code nearly line-for-line, but I'm seeing strange overlaps in my surfaces.

Does anyone have any suggestions as to what would cause such an issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你是暖光i 2024-08-12 09:35:46

对我来说,您似乎缺少启用深度缓冲区或者可能创建带有 z 缓冲区的帧缓冲区。 (这与游吟诗人写的类似)

glEnable(GL_DEPTH_TEST);

To me it looks like you are missing enabling the Depth buffer or maybe creating a framebuffer with a z-buffer. (this is similar to what Troubadour is writing)

glEnable(GL_DEPTH_TEST);
小苏打饼 2024-08-12 09:35:46

看来您的深度缓冲区有问题。特别是,看起来每个多边形的绘制都与深度无关,即来自多边形的每个片段都通过了深度测试。这意味着多边形只是按照它们渲染的顺序相互绘制。

禁用了对深度缓冲区的写入

glDepthMask( GL_FALSE )

您是否

?如果不是这样,那么您是否记得在每帧开始时清除深度缓冲区? Nehe 教程首先

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

清除深度和颜色缓冲区。确保您没有删除其中的 GL_DEPTH_BUFFER_BIT 部分。

华泰

Looks like you've got an issue with the depth buffer. In particular it looks like each polygon is being drawn without regard to depth i.e. each fragment coming from the polygons is passing the depth test. This would mean that the polygons are simply drawn over each other in whatever order they happen to be rendered in.

Did you disable writing to the depth buffer with something like

glDepthMask( GL_FALSE )

by any chance?

If it's not that then did you remember to clear the depth buffer at the beginning of each frame? The Nehe tutorial starts with

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

which clears both the depth and colour buffers. Make sure you haven't got rid of the GL_DEPTH_BUFFER_BIT part of that.

HTH

挽清梦 2024-08-12 09:35:46

哇,用一行就完全修复了它:

gl.glEnable(GL.GL_CULL_FACE);

我不知道它是做什么的,但我使用的任何教程中都没有提到它,但我的演示现在工作得很好。去谷歌看看它做了什么。 :D

Wow, completely fixed it with one line:

gl.glEnable(GL.GL_CULL_FACE);

I have no idea what it does, but it wasn't mentioned in any tutorials I used, but my demo works perfectly now. Off to Google to figure out what that did. :D

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文