1
\$\begingroup\$

I have a QT canvas and I'm using shaders to build my scence. I've set the camera image plane at some position, and would like to view object from the image plane to infinity. How do I set the zfar and znear values?

\$\endgroup\$
1
  • \$\begingroup\$ How are the objects distributed in your scene? If you have just one cluster of objects, you can set the near & far planes to the nearest & furthest edges of that cluster, to render them from any distance without an "infinite" far plane. If your objects are very widely spread, then you might need to render in multiple cascades - one for the furthest objects, then one for the nearer objects, so your depth buffer precision isn't spread too thin. \$\endgroup\$
    – DMGregory
    Oct 30, 2017 at 22:53

1 Answer 1

1
\$\begingroup\$

You can't make OpenGL render to infinity. The depth buffer usually uses floats (it can use other types, but none of them can represent an infinite number of values), meaning it has a set precision. If you set the zFar value to 100,000 for instance (not even close to infinity), then you'll have problems with z fighting between objects, that are hundreds of units apart from each other.

\$\endgroup\$
3
  • \$\begingroup\$ How do I set the zFar value? \$\endgroup\$
    – Mercury
    Nov 2, 2017 at 20:09
  • \$\begingroup\$ @Mercury stackoverflow.com/questions/20624582/… \$\endgroup\$
    – Bálint
    Nov 2, 2017 at 20:37
  • \$\begingroup\$ My drawing class has no camera member function... class Canvas : public QGLWidget, protected QGLFunctions{...}; Am I missing something basic? I've been trying to use glDepthRange(znear,zfar) with no effect... \$\endgroup\$
    – Mercury
    Nov 2, 2017 at 21:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .