I have this problem and would be most grateful if somebody can help me:
I render my scene and whenever I ‘move the camera’ (actually move the objects in opposite direction) a little far away the farther objects seen to be ‘eaten’ by a black wall.
It’s hard to phrase, but what I am trying to explain is that for example the big wooden table, as I get farther away, first looks smaller (as it should be), and then the triangles of the object seem to be cut by an ‘end of the screen’ and so the object appears half-complete.
How can I fix that!?
I get really far away the whole screen is covered in black, the wooden floor, and all my objects dissapear as they are covered by a black plane…
You have to increase the distance of the far plane in your projection matrix. There are no limits on the size of the scene in OpenGL, you can set the far plane to infinity even.
You probably use the gluPerspective function to set the projection matrix, just increase the far value.
The catch is that you have a fixed depth buffer resolution (usually 24 bits), and the bigger the distance between your near and far planes, the worse your precision will be, which eventually will show up as z-fighting.
I read the article, but I am working only with gluPerspective as you guessed right (!), and I don’t have the near parameter and those things the article mentions.
However I increased the far value in the gluperspective and it works fine!
I didn’t really understand the catch.
Does the article imply that if I put a big number for the far value, I will have a ‘greater world’, but will have less precision in the position of objects when I look them very close?
This is my init code:
Private Sub Form_Resize()
w = Me.ScaleWidth: h = Me.ScaleHeight
If h = 0 Then h = 1
glViewport 0, 0, w, h
gluPerspective 45#, w / h, 1#, 300#
Originally posted by Rodrix: I didn’t really understand the catch. Does the article imply that if I put a big number for the far value, I will have a ‘greater world’, but will have less precision in the position of objects when I look them very close?
Yes, something like that, although it’s not really about how close you look, because ‘close’ is relative. Imagine this: can you tell if a table is two meters long and is one meter away from you, or two thousand kilometres long and is one thousand kilometers away from you? (given that there’s no atmosphere, and no other objects to compare to, just the black void around it)? With regards to depth resolution, it’s not the far distance that counts, but the ratio of far vs near plane distance. If you rendered both tables, and had the near plane one centimeter from the camera, the small table would look right, while the large table would have terrible precision problems (textures flickering, etc), even though both object would look the same size on screen!
There are other precision issues that are not originated from the projection matrix, but from the finite resolution of floating point numbers used to describe vertex positions, but that’s another story for another day.
Looking far is not the problem. You can set your far plane to infinity even. Problems arise, when you want to see nearby details and far away vistas at the same time! Notice that most flight sims don’t let you do that. They don’t have too much resolution nearby so they can push the near plane far away. Still, it’s possible to do it, by subdividing your scene into multiple chunks, sorting them by distance and rendering them back to front, clearing the z-buffer between, or just using different depth ranges. Or another nice trick is to enable clamping of near Z values.
But these are advanced techniques, don’t worry about these for now