Advertisement

alternate method for glEnable(GL_DEPTH_CLAMP_NV)

Started by January 20, 2004 04:39 PM
2 comments, last by penetrator 21 years, 1 month ago
I find this extension very useful, but unfortunately it''s not supported by Ati cards. This article at Gamasutra ( http://www.gamasutra.com/features/20021011/lengyel_02.htm ) explains how to achieve the same goal modifying the projection matrix in order to achieve infinite view frustums. Unfortunately i don''t know how to solve the matrix equation at point 8 , converting it into c++ code. Could someone help ? Thanks
Havn''t read the article at gamesutra, but to move the far plane to infinity run this after setting the frustum with gluPerspective or whatever..

float Pinf[4][4];
glMatrixMode(GL_PROJECTION);

glGetFloatv(GL_PROJECTION_MATRIX, &Pinf[0][0]);
Pinf[3][2] = -2.0f*0.1f; // 2 * near
Pinf[2][2] = -1;
glLoadMatrixf(&Pinf[0][0]);
Advertisement
Hi Jot, using this code i get a complete white screen ...

That shouldn''t happen, it works for me.. You''re probably doing something different from me. My complete code for creating the frustum is:

glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fov*(float)height/(float)width,
(float)width/(float)height, 0.01, 500.0);

if( !extensions->hasDepthClamp() ){
glGetFloatv(GL_PROJECTION_MATRIX, &Pinf[0][0]);
Pinf[3][2] = -2.0f*0.1f; // 2 * near
Pinf[2][2] = -1;
glLoadMatrixf(&Pinf[0][0]);
}
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

Note that I changed behaviour so fov is horizontal fov instead of vertical, that''s why the code looks non-standard

This topic is closed to new replies.

Advertisement