PDA

View Full Version : Getting the modelview matrix



Agoston Bejo
01-01-2005, 12:24 PM
Hi there,
I'm absolutely a beginner, so sorry if the question is silly. What I'm trying to

do is quite simple: I'm trying to get the modelview matrix into an array of

doubles. After the following lines:

GLdouble matrix[4][4];
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glGetDoublev(GL_MODELVIEW_MATRIX, &matrix[0][0]);

matrix should contain the identity matrix, but it will only contain garbage.

What am I doing wrong? The documentation states quite explicitly that glGet...()

returns the modelview matrix with the above parameter.

Thx,
Agoston

iznogoud
01-01-2005, 12:39 PM
Very strange! I simply dumped this right after I reset
my MODELVIEW matrix to the identity and I get the
correct results



{
GLdouble matrix[4][4];
glGetDoublev(GL_MODELVIEW_MATRIX, &matrix[0][0]);
printf("%f, %f, %f, %f\n",matrix[0][0],matrix[1][0],matrix[2][0],matrix[3][0]);
printf("%f, %f, %f, %f\n",matrix[0][1],matrix[1][1],matrix[2][1],matrix[3][1]);
printf("%f, %f, %f, %f\n",matrix[0][2],matrix[1][2],matrix[2][2],matrix[3][2]);
printf("%f, %f, %f, %f\n",matrix[0][3],matrix[1][3],matrix[2][3],matrix[3][3]);
exit(0);
}
My setup: GNU/Linux (Slackware) 2.4.18, DRI MESA on Voodoo 3 for XFree86 4.2.

Why don't you try to get an error code (errno) right
after the glGetDoublev ? This might help.

Omaha
01-01-2005, 09:51 PM
Define "garbage" and how are you accessing the members of the matrix array?

Also, life can be made a little simpler by just using a one dimensional 16 element array to store matrices for interaction with OGL.