enlarge the view volume's depth

Hi,

At some moment, my object cannot be seen because it is rotated outside the space between nearer and farther depth clipping planes. To make it visible, I want to do the following:

glGetDoublev(GL_PROJECTION_MATRIX, aProj);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

// change the depth
glOrtho(-w, w, -h, h, -z, +z);
… rendering the object
glPopMatrix();

With the knowledge of the object’s coordinates and aProj, is it possible to determine the value of z? What else do I need before z’s value can be got?

Thanks very much if you can provide any hint.

Tony

In principle, you can read back the depth buffer using glReadPixels.

But the depth buffer is usually not linear, and I’m not sure glReadPixels compensates for that.

Play around a bit with this page:
http://www.sjbaker.org/steve/omniv/love_your_z_buffer.html - and look in the bluebook at the glFrustum command - these may give you some clue as to the formula used for computing the actual vale in the depth buffer.


Now that that’s out of the way, I’m wondering if it wouldn’t be simpler to calculate it from the source though.

With an Ortho projection, which you appear to be using, that should be very simple indeed:

  1. for every vertex, determine the minimum/maximum X/Y/Z
  2. Use those to set the projection.