Here is a link for redbook online: http://fly.cc.fer.hr/~unreal/theredbook/chapter12.html
Example 12.3 shows picking.
For picking it uses following code:
…
glMatrixMode (GL_PROJECTION);
glPushMatrix ();
glLoadIdentity ();
/* create 5x5 pixel picking region near cursor location */
gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3] - y), 5.0, 5.0, viewport);
gluOrtho2D (0.0, 3.0, 0.0, 3.0);
drawSquares (GL_SELECT);
glPopMatrix ();
glFlush ();
…
1)As shown above, pickSquares method sets up the picking, ie. render mode, gluPickMatrix(…) etc. While doing that it changes GL_MATRIX_MODE to GL_PROJECTION, but doesn’t set that back to GL_MODELVIEW. For drawing nething, the matrix mode must be GL_MODELVIEW, right? Then how does this example work?
- In the reshape ,method it already has
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D (0.0, 3.0, 0.0, 3.0);
So, in the Projection Matrix stack there is the correct matrix for projection,
Now, while picking, that matrix is pushed down and the stack top is replaced by identity, and then gluPickMatrix()… etc. after picking its poped out.
So, WHILE picking the projection matrix-Stack
contains the original matrix at the bottom (inserted in reshapeFunc) and a new one at the top, (inserted by the picking code)
Actually the correct matrix to have is ONLY the top one…, right?
Then how does the example work correctly?
- Chetan
[This message has been edited by virtualchetan (edited 10-10-2003).]