如何增加 openGL 停止绘制对象的距离(zfar/gluPerspective)?

发布于 2024-10-22 00:56:51 字数 1087 浏览 3 评论 0原文

我正在学习 OpenGL,但遇到了 gluPerspective 的问题。这是我在 Init() 中使用的代码,

// Calculate The Aspect Ratio Of The Window
// The parameters are:
// (view angle, aspect ration of the width to the height, 
//  The closest distance to the camera before it clips, 
// FOV, Ratio,  The farthest distance before it stops drawing)
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height, 0.5f, 3000.0f);

我的场景工作正常..但是一旦我稍微远离我的对象,它们就会消失(如图像中的红球)。 : Frustrum 示例 我从中获取图表的网站

我知道红球在视野之外,不会被显示。所以我想要的是增加它停止绘制的距离。我尝试增加 3000.0f 但不起作用!

    gluPerspective(45.0f,(GLfloat)width/(GLfloat)height, 0.5f, 3000000.0f);

所以我的问题是:如何增加 openGL 停止绘制对象的距离?

有关该问题的一些图片: 图片1 图片2

I am learning OpenGL and having a problem with gluPerspective. Here is the code I use in Init()

// Calculate The Aspect Ratio Of The Window
// The parameters are:
// (view angle, aspect ration of the width to the height, 
//  The closest distance to the camera before it clips, 
// FOV, Ratio,  The farthest distance before it stops drawing)
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height, 0.5f, 3000.0f);

My scene works right.. but as soon as I go a little bit away from my objects they dissapear (As the red balls in image). : Frustrum example
Web where I took graph from

I understand that red balls are outside of view and won't be shown. So what I want is to increase the distance where it stops drawing. I tried increasing 3000.0f but is not working!.

    gluPerspective(45.0f,(GLfloat)width/(GLfloat)height, 0.5f, 3000000.0f);

So my question is : How can I increase distance where openGL stops drawing objects?

Some pics about the problem:
Pic1
Pic2

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

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

发布评论

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

评论(2

滥情空心 2024-10-29 00:56:51

我弄清楚发生了什么,所以我自己回答这个问题,以帮助将来的其他人:

更改 zfar 可以正常工作。我遇到的问题是(为了简化而未包含在问题中)是我的天空盒。 Skybox 很小,将物体隐藏在天空中。在 pic2 中很容易看到!

因此,如果您遇到类似的问题,只需仔细检查您的天空盒即可。如果这是一个 zfar 问题,一切都应该
是黑色而不是天空纹理!

I figured out what was happening so I answer this myself to help other people in the future:

Changing zfar works ok. The problem I had was (not included in the question for simplification) was my skybox. Skybox was small and was hiding the objects with the sky. In pic2 is easy to see!

So if you have a similar problem just double check your skybox. If it were a zfar problem everthing should
be black instead of having a sky texture!

云淡月浅 2024-10-29 00:56:51

近和远值定义深度缓冲区的精度。近端和远端之间的比率越高,您获得的深度缓冲区精度误差就越大。因此,您的深度缓冲区实际上可能允许绘制对象,但如果它们很小并且彼此靠近,它们仍然可能不可见(被拒绝或被透支)。

如果从 3000.0f 增加到 10000.0f,它可能仍然有效。你的物体有多大?

首先为什么需要这么大的观看距离?也许还有其他方法更适合您的需求。

The near and far values define the precision of the depth buffer. The higher the ratio between near and far is the more depth buffer precision errors you will get. Thus your depth buffer might actually allow to draw the objects but if they are small and close to each other they still might not be visible (rejected or be overdrawn).

If you increase from 3000.0f to 10000.0f it might still work. How big are your objects?

Why do you need that big viewing distance in the first place? Maybe there are other approaches that better fit your needs.

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