May need pushName(-1);
glSelectBuffer(size, buffer); /* initialize */ glRenderMode(GL_SELECT); glInitNames(); glPushName(-1); glGetIntegerv(GL_VIEWPORT,viewport); /* set up pick view */ glMatrixMode(GL_PROJECTION); glPushMatrix(); glIdentity(); gluPickMatrix(x,y,w,h,viewport); glMatrixMode(GL_MODELVIEW); ViewMatrix(); glLoadName(1); Draw1(); glLoadName(2); Draw2(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); hits = glRenderMode(GL_RENDER);
/* initialization stuff goes here */ glPushName(1); Draw1(); /* stack: 1 */ glPushName(1); Draw1_1(); /* stack: 1 1 */ glPushName(1); Draw1_1_1(); /* stack: 1 1 1 */ glPopName(); glPushName(2); Draw1_1_2(); /* stack: 1 1 2 */ glPopName(); glPopName(); glPushName(2); /* stack: 1 2 */ Draw1_2(); glPopName(); glPopName(); glPushName(2); Draw2(); /* stack: 2 */ glPopName(); /* wrap-up stuff here */
Readings: GL Programming Manual, Chapter 12