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);
glLoadIdentity();
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);
glLoadIdentity();
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);
glLoadIdentity();
glOrtho(left,right,bottom,top,1.0, 500.0); //how????
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
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.