glPopMatrix does not get what was pushed

Started by
2 comments, last by BitMaster 10 years, 6 months ago

Hello,

I have noticed that I don't get the same matrix I pushed !!

Does anybody have an idea ?

Thank you

Here is the code I am using:

#include <assert.h>

int DrawGLScene(GLvoid)
{
rtri+=.2f;
GLdouble mat5[16],mat6[16];
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(rtri,0.0f,1.0f,0.0f);
glGetDoublev(GL_MODELVIEW_MATRIX, (GLdouble *)&mat5);
glPushMatrix();
glPopMatrix();
glGetDoublev(GL_MODELVIEW_MATRIX, (GLdouble *)&mat6);
assert(matequal(mat5,mat6)); <----- execution breaks here
}
bool matequal(GLdouble *N,GLdouble *M)
{
if(
M[0]==N[0] && M[1]==N[1] && M[2]==N[2] && M[3]==N[3] &&
M[4]==N[4] && M[5]==N[5] && M[6]==N[6] && M[7]==N[7] &&
M[8]==N[8] && M[9]==N[9] && M[10]==N[10] && M[11]==N[11] &&
M[12]==N[12] && M[13]==N[13] && M[14]==N[14] && M[15]==N[15] )
return true;
return false;
}
Advertisement

Is it widely different?

glPush/PopMatrix() should just be a memcpy() call internally

From reading your code, I can see nothing wrong. Your results are puzzling smile.png

I'm not entirely sure why you would expect anything with GPU to be double-precision though.. tongue.png

The drivers will just convert everything to float, but there is nothing in your code that shouldn't return the same values both times

Although, try using glGetFloatv instead, just to see if it's a precision issue

I probably should mention that using == with floating point numbers, with few exceptions (one being this case), is generally dangerous :)

http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

I am Sorry.

It was my mistake :

I had one glPushMatrix in excess elsewhere in the code. So at the end of each frame, I had a matrix forgotten in the stack.

and at the 32nd frame, the matrix poped no longer corresponded to the one immediately pushed.

I guess openGL should signal the overflow in the matrix stack by a crash or a warning, rather than poping an incorrect matrix.

Thank you for your answer and your time

According to the docs, GL_STACK_OVERFLOW can be generated. However, since this is completely deprecated functionality it is of course possible modern drivers don't bother anymore.

This topic is closed to new replies.

Advertisement