Can someone explain the functionally of each of the following OpenGL functions?
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, (GLdouble)w, 0.0, (GLdouble)h, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Remember that OpenGL works as a state machine.
glMatrixMode(GL_PROJECTION);
Sets the current matrix to be the projection matrix, i.e. the active matrix state is the projection matrix, so all subsequent matrix calls will affect the projection matrix. The projection matrix deals with how things are viewed (how the camera is setup).
glLoadIdentity();
Sets the value of the current matrix to the identity matrix. The current matrix is the projection matrix.
glOrtho(0.0, (GLdouble)w, 0.0, (GLdouble)h, -1.0, 1.0);
From OpenGl's documentation: "multiply the current matrix with an orthographic matrix". Thus, the projection matrix (think of the camera) is transformed to show an orthographic perspective.
glMatrixMode(GL_MODELVIEW);
Sets the current matrix to be the model view matrix. The model view matrix deals with how objects are displayed. Model view transformations could rotate or translate objects.
So basically the first three lines set up the camera and the last two make the current matrix the model view matrix because the program is done setting up the camera and needs to display the objects. There isn't an actual camera in OpenGL. The idea of a camera is just a common analogy.