ntraft

04-06-2009, 10:55 AM

Just curious:

It is well documented that gluPickMatrix must be called on the identity matrix, BEFORE setting up the projection matrix with gluPerspective. But why?

I can't find anything that says why the multiplication has to occur in this order. It would be nice if all I had to do was push the current matrix onto the stack and call pickMatrix:

glMatrixMode(GL_PROJECTION);

glPushMatrix();

glPickMatrix(x, y, 1, 1, viewport);

glMatrixMode(GL_MODELVIEW);

...draw stuff...

glMatrixMode(GL_PROJECTION);

glPopMatrix();

Instead, I have to store the field of view and aspect ratio, load the identity matrix, create the pick matrix, and then finally restore the projection matrix I had in the first place:

glMatrixMode(GL_PROJECTION);

glPushMatrix();

glLoadIdentity();

glPickMatrix(x, y, 1.0f, 1.0f, viewport);

glPerspective(fov_y, aspect, near, far);

glMatrixMode(GL_MODELVIEW);

...draw stuff...

glMatrixMode(GL_PROJECTION);

glPopMatrix();

So, again, why can't I do it the first way (so that I can use the same code no matter what kind of projection/ortho matrix I'm working with)?

It is well documented that gluPickMatrix must be called on the identity matrix, BEFORE setting up the projection matrix with gluPerspective. But why?

I can't find anything that says why the multiplication has to occur in this order. It would be nice if all I had to do was push the current matrix onto the stack and call pickMatrix:

glMatrixMode(GL_PROJECTION);

glPushMatrix();

glPickMatrix(x, y, 1, 1, viewport);

glMatrixMode(GL_MODELVIEW);

...draw stuff...

glMatrixMode(GL_PROJECTION);

glPopMatrix();

Instead, I have to store the field of view and aspect ratio, load the identity matrix, create the pick matrix, and then finally restore the projection matrix I had in the first place:

glMatrixMode(GL_PROJECTION);

glPushMatrix();

glLoadIdentity();

glPickMatrix(x, y, 1.0f, 1.0f, viewport);

glPerspective(fov_y, aspect, near, far);

glMatrixMode(GL_MODELVIEW);

...draw stuff...

glMatrixMode(GL_PROJECTION);

glPopMatrix();

So, again, why can't I do it the first way (so that I can use the same code no matter what kind of projection/ortho matrix I'm working with)?