I have the following code.
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eyeX+eyePos, eyeY, eyeZ, lookatX+eyePos, lookatY, lookatZ, upX, upY, upZ);
glGetDoublev(GL_MODELVIEW_MATRIX,lookatMatrix);
glPushMatrix();
So we have a matrix after gluLookAt, and I presume it stores on top of current matrix mode stack. Now, we get the value out of it using GetDoulev, Then why do use glPushMatrix in the end?
glPushMatrix keeps a copy around so that you can do further manipulations on the matrix stack yet are able to easily revert to a previous state using glPopMatrix.
But truth be told, don't use it. The matrix stack has been removed from modern OpenGL and it's far more convenient to use a real matrix math library, like GLM, than doing awkward things with the OpenGL matrix stack. The moment you use glGetDoublev(GL_…_MATRIX, …)
so that you can do further things with said matrix, you're doing something wrong.
Just use a real matrix math library and load whatever matrix you need at the moment using glLoadMatrix (if you absolutely have to use the old style fixed function pipeline) or load it into a shader uniform (which is what you should absolutely do whenever you can use modern OpenGL).