Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: Opengl Eats the screen

  1. #1
    Member Regular Contributor
    Join Date
    Dec 2005
    Posts
    256

    Opengl Eats the screen

    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!?
    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!

  2. #2
    Junior Member Regular Contributor
    Join Date
    May 2005
    Location
    boulder, co
    Posts
    228

    Re: Opengl Eats the screen

    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.

    Recommended reading:
    http://www.sjbaker.org/steve/omniv/l..._z_buffer.html

  3. #3
    Member Regular Contributor
    Join Date
    Dec 2005
    Posts
    256

    Re: Opengl Eats the screen

    Hi!
    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
    glMatrixMode GL_PROJECTION
    glLoadIdentity
    gluPerspective 45#, w / h, 1#, 300#
    glMatrixMode GL_MODELVIEW
    glLoadIdentity
    end sub

    Thank you so much again!

    P.S: Readings welcome!

  4. #4
    Junior Member Regular Contributor
    Join Date
    May 2005
    Location
    boulder, co
    Posts
    228

    Re: Opengl Eats the screen

    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.

  5. #5
    Member Regular Contributor
    Join Date
    Dec 2005
    Posts
    256

    Re: Opengl Eats the screen

    It took me some time to think it over and test it!
    But I think I got it!

    Thank you soooooo much!

  6. #6
    Member Regular Contributor
    Join Date
    Dec 2005
    Posts
    256

    Re: Opengl Eats the screen

    .....Hey but then how do flight simulation games display so detailed terrain and stuff so far away from the viewer?!

    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?!

    Thanks again!

  7. #7
    Junior Member Regular Contributor
    Join Date
    May 2005
    Location
    boulder, co
    Posts
    228

    Re: Opengl Eats the screen

    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

  8. #8
    Member Regular Contributor
    Join Date
    Dec 2005
    Posts
    256

    Re: Opengl Eats the screen

    Thanks so much!
    I will have it in mind if I ever need it! (however, I hope I don't... haha)
    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •