开发者

How can I increase distance (zfar/gluPerspective) where openGL stops drawing objects?

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开发者_如何学C 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). :

How can I increase distance (zfar/gluPerspective) where openGL stops drawing objects?

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


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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜