glInitNames();
glPushName(0);
glPushMatrix(); /* save the current transformation state */
for(int i=0;i<n;i++) {
glLoadName(1+i);
drawEntity(i);
}
glPopMatrix (); /* restore the previous transformation state*/
Following are the important OpenGL name manipulation API used selection mode:
void glInitNames(void);
//Clears the name stack so that it's empty.
void glPushName(GLuint name);
//Pushes name onto the name stack.
void glPopName(void);
//Pops one name off the top of the name stack.
void glLoadName(GLuint name);
/*Replaces the value on the top of the name stack with name. If the stack is empty, which it is right after glInitNames() is called, glLoadName() generates the error GL_INVALID_OPERATION. To avoid this, if the stack is initially empty, call glPushName() at least once to put something on the name stack before calling glLoadName().*/