/************************************************************************ Handy functions for common OpenGL tasks $Id: gltools.cxx 446 2005-06-18 13:58:15Z garland $ ************************************************************************/ #include #ifdef HAVE_OPENGL #include #include namespace gfx { using std::cerr; using std::endl; GLuint opengl_pick_nil = (~0); GLuint opengl_pick_zmax = (~0); void begin_opengl_pick(int *where, double radius, GLuint *buffer, int size) { GLint vp[4]; glGetIntegerv(GL_VIEWPORT, vp); glSelectBuffer(size, buffer); glRenderMode(GL_SELECT); glInitNames(); glPushName(opengl_pick_nil); glMatrixMode(GL_PROJECTION); glPushMatrix(); // Save the current transformation glLoadIdentity(); gluPickMatrix(where[0], vp[3] - where[1], radius, radius, vp); } GLuint complete_opengl_pick(GLuint *buffer) { glMatrixMode(GL_PROJECTION); glPopMatrix(); // get rid of the pick matrix glFlush(); GLint nhits = glRenderMode(GL_RENDER); GLuint *hit = NULL; GLuint hit_nnames = 0; GLuint zmin = opengl_pick_zmax; GLuint *ptr = buffer; for(int i=0; i