View Full Version : Opengl Eats the screen
01-27-2006, 05:24 PM
Hi everyone! I hope you had all a great new year! :)
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!? :confused:
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...
Does OpenGl have limits on the world size!?
Thank you very much in advace! :)
01-27-2006, 06:39 PM
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.
01-27-2006, 08:28 PM
Thank you so much for such a fast reply! :) :) :)
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#
Thank you so much again!
P.S: Readings welcome! :)
01-28-2006, 07:24 AM
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. ;)
02-01-2006, 06:31 PM
It took me some time to think it over and test it!
But I think I got it! :)
Thank you soooooo much! :)
02-01-2006, 06:34 PM
.....Hey but then how do flight simulation games display so detailed terrain and stuff so far away from the viewer?! :confused:
Is there a work around for this z-buffer thingy?
Or is the screen really eaten up but its so far away that the user doesnt perceive it?!
02-02-2006, 08:52 AM
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 ;)
02-03-2006, 09:36 AM
Thanks so much!
I will have it in mind if I ever need it! (however, I hope I don't... haha) :)
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.