   GLUT Picking
  Im trying to create a pick function with GLUT.My program should be able to rotate, pan, zoom around in the 3d view and picking the objects.I have tried looked at Redbook''s pickDepth... It works fine.. But the problem now is to implant a zoom function to pickDepth.I have created a zoom function and the picking works fine just when you open the prog.. But it doesen''t work if you zoom and then try picking something..Here''s the code:#include <stdlib.h>#include <stdio.h>#include <GL/glut.h>int tz = -16;int mx;bool right = false;int ww;int wh;void myinit(void){  glClearColor(0.0, 0.0, 0.0, 0.0);  glDepthFunc(GL_LESS);  glEnable(GL_DEPTH_TEST);  glShadeModel(GL_FLAT);  glDepthRange(0.0, 1.0);  /* The default z mapping */}void drawRects(GLenum mode){glTranslatef(0,0, tz);  if (mode == GL_SELECT)    glLoadName(1);  glBegin(GL_QUADS);  glColor3f(1.0, 1.0, 0.0);  glVertex3i(2, 0, 0);  glVertex3i(2, 6, 0);  glVertex3i(6, 6, 0);  glVertex3i(6, 0, 0);  glEnd();  if (mode == GL_SELECT)    glLoadName(2);  glBegin(GL_QUADS);  glColor3f(0.0, 1.0, 1.0);  glVertex3i(3, 2, -1);  glVertex3i(3, 8, -1);  glVertex3i(8, 8, -1);  glVertex3i(8, 2, -1);  glEnd();  if (mode == GL_SELECT)    glLoadName(3);  glBegin(GL_QUADS);  glColor3f(1.0, 0.0, 1.0);  glVertex3i(0, 2, -2);  glVertex3i(0, 7, -2);  glVertex3i(5, 7, -2);  glVertex3i(5, 2, -2);  glEnd();}void processHits(GLint hits, GLuint buffer[]){  int i;  unsigned int j;  GLuint names, *ptr;  printf("hits = %d\n", hits);  ptr = (GLuint *) buffer;  for (i = 0; i < hits; i++) {  /* for each hit  */    names = *ptr;    printf(" number of names for hit = %d\n", names);    ptr++;    printf("  z1 is %g;", (float) *ptr/0xffffffff);    ptr++;    printf(" z2 is %g\n", (float) *ptr/0xffffffff);    ptr++;    printf("   the name is ");    for (j = 0; j < names; j++) {  /* for each name */ printf("%d ", *ptr); ptr++;    }    printf("\n");  }}#define BUFSIZE 512void pickRects(int button, int state, int x, int y){if (state == GLUT_DOWN && button == GLUT_RIGHT_BUTTON){right = true;}if (state == GLUT_UP && button == GLUT_RIGHT_BUTTON){right = false;}mx = x;  GLuint selectBuf[BUFSIZE];  GLint hits;  GLint viewport[4];  if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN)    return;  glGetIntegerv(GL_VIEWPORT, viewport);  glSelectBuffer(BUFSIZE, selectBuf);  (void) glRenderMode(GL_SELECT);  glInitNames();  glPushName((GLuint) ~0);  glMatrixMode(GL_PROJECTION);  glPushMatrix();  glLoadIdentity();  gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3] - y),    1.0, 1.0, viewport);  gluPerspective(45.0f,   ww/wh,  -0.5, 2.5);  drawRects(GL_SELECT);  glPopMatrix();  glFlush();  hits = glRenderMode(GL_RENDER);  processHits(hits, selectBuf);    glMatrixMode(GL_MODELVIEW);}void display(void){  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);   glColor3f (1.0, 1.0, 1.0);   glLoadIdentity();    drawRects(GL_RENDER);  glutSwapBuffers();}void myReshape(int w, int h){ww = w;  wh = h;  glViewport(0, 0, w, h);  glMatrixMode(GL_PROJECTION);  glLoadIdentity();  gluPerspective(45.0f,  w/h,  -0.5, 2.5);  glTranslatef(0,0, tz);  glMatrixMode(GL_MODELVIEW);  glLoadIdentity();}void mouseMove(int x, int y){if (right){tz -= (mx - x);mx = x;glutPostRedisplay();}}intmain(int argc, char **argv){  glutInitWindowSize(500, 500);  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);  glutInit(&argc, argv);  glutCreateWindow(argv[0]);  myinit();  glutReshapeFunc(myReshape);  glutDisplayFunc(display);    glutMouseFunc(pickRects);  glutMotionFunc(mouseMove);  glutMainLoop();  return 0;   } 
  Nevermind, i got it now. 