问题
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). :
Web where I took graph fromI 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
回答1:
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!
回答2:
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.
来源:https://stackoverflow.com/questions/5300888/how-can-i-increase-distance-zfar-gluperspective-where-opengl-stops-drawing-obj