# Can we flip znear and zfar so that positive z values increase away from the viewer?

I am confused about the projection matrix in OpenGL.

i have a habit of writing the code as follows.

glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
if(w<=h)
glOrtho(0.0f,250.0f,0.0f,250.0f*h/w,1.0,-1.0);
else
glOrtho(0.0f,250.0f*w/h,0.0f,250.0f,1.0,-1.0);
glMatrixMode(GL_MODELVIEW);


Simple, This code sets the viewing clipping region that maintains the equal width and height. negative z value points away from the viewer. as z value extends from 1 to -1. anything that lies outside this value wont be visible to the user. But i have seen the code like this.

glMatrixMode(GL_PROJECTION);
glOrtho(left,right,bottom,top,1.0, 500.0);  //how????
glMatrixMode(GL_MODELVIEW);
glTranslatef(0.0f, 0.0f, -250.0f);       ///?????
glutSolidSphere(15.0f,15,15);           /// how is this visible on the screen
}


Please help me understand this code. As from my point of view the z value is totally flipped near is 1.0 its okay but zfar is 500 and following that code there is a translation of z value to -250. and drawing that sphere will be visible on the screen how? My question is can we flip znear and zfar so that positive z value will go away from the viewer.

• The glOrtho call appears to be made with predefined variables to avoid using magic numbers.
• The glTranslatef call will move the origin 250 units into the scene, since by default, the coordinate system points outward. However, from the rest of your post it appears you already knew this, so I'm unsure of what to make of this comment.
• The glutSolidSphere call just puts a sphere at the origin of the scene. Since the origin was just moved 250 units into the scene, the sphere appears at [0, 0, -250] relative to the camera.
As for the rest of your question, I suspect you want to use glScalef(1.0, 1.0, -1.0); to reflect your coordinate system across the XY plane.