glGetDoublev returns 0-Matrix

I’ve used the glGetDoublev function to get the modelview matrix but the function returns me an array with every value set to 0. I tried also to get the porjection matrix and get the same result. Here’s a function that calls glGetDoublev before a call of gluLookAt and after that call. Both calls of glGetDoublev returns this result:

void setModelview(void)
GLdouble temp[16];
// setup model matrix
glGetDoublev(GL_MODELVIEW_MATRIX, temp); // get modelview-matrix
gluLookAt(0.0, 0.0, 100.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glGetDoublev(GL_MODELVIEW_MATRIX, temp); // get modelview-matrix

I’ve no more ideas why this happens…

I’ve noticed the failure occurs ONLY when I call glGetDoublev with parameter GL_MODELVIEW_MATRIX and NOT with parameter GL_PROJECTION_MATRIX.

Are you sure that OpenGL context already created and active at time you call correspondent functions?

hmmm, I don’t know. I’m very new to GL. There is the function displayWorld as follows:

	GLdouble temp[16];
	GLfloat _directionalVec[] = { 0.0, 0.0, 1.0, 0.0 };



	glClearColor(0.2, 0.2, 0.2, 0.0);
	// set Light position
	glLightfv(GL_LIGHT0, GL_POSITION, _directionalVec);

	// shift object
	glTranslatef(_shiftX, _shiftY, _shiftZ);

	// rotate Object
	glRotatef(_rotObjectX, 1.0f, 0.0f, 0.0f);
	glRotatef(_rotObjectY, 0.0f, 1.0f, 0.0f);

	// show coordinate system
	if(_showCoordinates == ON)
			glColor3ub(255, 0, 0);
			glVertex3f(0.0, 0.0, 0.0);
			glVertex3f(5.0, 0.0, 0.0);

			glColor3ub(0, 255, 0);
			glVertex3f(0.0, 0.0, 0.0);
			glVertex3f(0.0, 5.0, 0.0);

			glColor3ub(0, 0, 255);
			glVertex3f(0.0, 0.0, 0.0);
			glVertex3f(0.0, 0.0, 5.0);

	// show center of spherical mapping
	if(_showOrigin == ON)
		glColor3f(1.0, 1.0, 0.0);
		glTranslatef(_origin[0], _origin[1], _origin[2]);
		glutSolidSphere(1.0f, 20, 20);

	// shade and draw the geometry


the function setModelview() is called in the upper part and the drawOffModel function (which draws the model) is the last line before glutSwapBuffers() is called to output the result.
GL works from the last call to the first so there should be a modelviewmatrix at the moment I call the glGetDoublev(GL_MODELVIEW_MATRIX,… ) function (or is this wrong?).

I don’t know what the problem is, but if I shift the model arround then the modelview matrix is not filled with 0 any longer. Someone knows an answer on it?

The next problem I have is thet when I call glGetIntergerv(GL_VIEWPORT, viewport); the returned values are:
viewport[0] => 0
viewport[1] => 512
viewport[2] => -858993460
viewport[3] => -858993460
It’s easy to see that there is a failure because width and height is negative. The values should be:
viewport[0] => 0
viewport[1] => 0
viewport[2] => 1024
viewport[3] => 512

thanks for help

every time I’ve seen this problem, it’s been because the context wasn’t current.

double and triple check that your context is current before making the calls to glGet*.

how could this be? I call this function by a popup menu entry.

which compiler/debugger you use and how you look into variable’s values? Values -858993460 tells that those variable stay uninitialized… It seems to me like you look for variables values in VC7.NET IDE with “release” build option. But in any case I suggest to make some kind of output into file and take a look at values there and not in debugger, just for sure…

the compiler I use is the one that comes with visual c++ 2005 beta. the variable is initialized with 0 but this is the output of the glGetIntegerv call. after the call I output the values with printf(“Value of viewport: %i, %i, %i, %i”, viewport[0], viewport[1],…);