i’ve read that OpenGL has the option to turn off clipping gainst the near and far planes and instead clamp the generated depth values to the range zero to one. This means that any geometry that protrudes behind the near plane or past the far plane will essentially be projected onto that plane. To enable depth clamping you must call glEnable(GL_DEPTH_CLAMP) and to disable, glDisable(GL_DEPTH_CLAMP).
My problem is that depth clamping is only working for the near plane, but is not working for the far plane.
my code is this:
//setting up matrix with nearplane=1 and farplane=10
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1,1,-1,1,1,10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
//i eanble depth clamping
glEnable(GL_DEPTH_CLAMP);
glClearColor(0,0,0,1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//i draw a triangle with 2 vertices inside the view frustum
//and 1 vertice outside , beyond the far plane
glBegin(GL_TRIANGLES);
glVertex4f(0,0,-100,1);
glVertex4f(-1,-1,-2,1);
glVertex4f(1,-1,-2,1);
glEnd();
glFlush();
//end
i compile and run, but i don’t see any clamping, but just the usual clipping.I don’t see a triangle, but i see a quadrilateral cutted on the far plane. Just like depth clamping was disabled. But strange thing, depth clamping on the near plane is working. Anyone knows why?
PS: i’m running ubuntu, nvidia GTX460, driver downloaded from nvidia web site.