makeCurrent();
GLuint selectBuf[BUFSIZE];
GLint hits;
GLint viewport[4];
glSelectBuffer (BUFSIZE, selectBuf);
glGetIntegerv(GL_VIEWPORT, viewport);
glRenderMode (GL_SELECT);
glInitNames();
glPushName(0);
glMatrixMode (GL_PROJECTION);
glPushMatrix ();
glLoadIdentity ();
gluPickMatrix((GLdouble) x, (GLdouble)(viewport[3] - y),
2.0, 2.0, viewport);
glOrtho(-3.5, +3.5, +3.5, -3.5, 2.0, 15.0);
glMatrixMode (GL_MODELVIEW);
glLoadName(1);
glBegin(GL_TRIANGLES);
glVertex3d(0.0, 2.0, 0.0);
glVertex3d(-2.0,-2.0, 2.0);
glVertex3d(2.0,-2.0, 2.0);
glEnd();
glLoadName(2);
glBegin(GL_TRIANGLES);
glVertex3d(0.0,2.0,0.0);
glVertex3d(2.0,-2.0,2.0);
glVertex3d(2.0,-2.0,-2.0);
glEnd();
glLoadName(3);
glBegin(GL_TRIANGLES);
glVertex3d(0.0,2.0,0.0);
glVertex3d(2.0,-2.0,-2.0);
glVertex3d(-2.0,-2.0,-2.0);
glEnd();
glLoadName(4);
glBegin(GL_TRIANGLES);
glVertex3d(0.0,2.0,0.0);
glVertex3d(-2.0,-2.0,-2.0);
glVertex3d(-2.0,-2.0, 2.0);
glEnd();
glLoadName(5);
glBegin(GL_QUADS);
glVertex3d(2.0,-2.0,2.0);
glVertex3d(-2.0,-2.0,2.0);
glVertex3d(-2.0,-2.0,-2.0);
glVertex3d(2.0,-2.0,-2.0);
glEnd();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glFlush();
hits = glRenderMode (GL_RENDER); // Returns no.of mouse hits to each face.
makeCurrent();
GLuint selectBuf[BUFSIZE];
GLint hits;
GLint viewport[4];
glSelectBuffer (BUFSIZE, selectBuf);
glGetIntegerv(GL_VIEWPORT, viewport);
glRenderMode (GL_SELECT);
glInitNames();
glPushName(0);
glMatrixMode (GL_PROJECTION);
glPushMatrix ();
glLoadIdentity ();
gluPickMatrix((GLdouble) x, (GLdouble)(viewport[3] - y),
2.0, 2.0, viewport);
glOrtho(-3.5, +3.5, +3.5, -3.5, 2.0, 15.0);
glMatrixMode (GL_MODELVIEW);
glLoadName(1);
glBegin(GL_TRIANGLES);
glVertex3d(0.0, 2.0, 0.0);
glVertex3d(-2.0,-2.0, 2.0);
glVertex3d(2.0,-2.0, 2.0);
glEnd();
glLoadName(2);
glBegin(GL_TRIANGLES);
glVertex3d(0.0,2.0,0.0);
glVertex3d(2.0,-2.0,2.0);
glVertex3d(2.0,-2.0,-2.0);
glEnd();
glLoadName(3);
glBegin(GL_TRIANGLES);
glVertex3d(0.0,2.0,0.0);
glVertex3d(2.0,-2.0,-2.0);
glVertex3d(-2.0,-2.0,-2.0);
glEnd();
glLoadName(4);
glBegin(GL_TRIANGLES);
glVertex3d(0.0,2.0,0.0);
glVertex3d(-2.0,-2.0,-2.0);
glVertex3d(-2.0,-2.0, 2.0);
glEnd();
glLoadName(5);
glBegin(GL_QUADS);
glVertex3d(2.0,-2.0,2.0);
glVertex3d(-2.0,-2.0,2.0);
glVertex3d(-2.0,-2.0,-2.0);
glVertex3d(2.0,-2.0,-2.0);
glEnd();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glFlush();
hits = glRenderMode (GL_RENDER); // Returns no.of mouse hits to each face.
To copy to clipboard, switch view to plain text mode
Bookmarks