Hi all,
i’m fairly new to opengl and this is my first time using the selection features so i’m kinda confused and please bear with me… i followed the example from the big red book but nothing seems to be happening in my program…
here’s what i’m trying to do…
i have a 3d object (triangle mesh) and when i click on this object i need to find the closest point on its surface to the mouse position. btw i’m using fltk as the GUI constructor, if relevant…
so here’s what i’m thinking of doing:
for each triangle in the mesh, assign a name - so in my draw function, i did a glLoadName(triangle_num) for each triangle drawn (before glBegin())… i didn’t check if i’m in selection mode since i read somewhere that if mode != GL_SELECT the call to glLoadName will simply be ignored - not sure if this is true…
then, in my mouse handle function i did the following:
//if the right mouse button is clicked…
int viewport[4];
GLint hits;
GLuint selectBuf[BUFSIZE];
glGetIntegerv( GL_VIEWPORT, viewport );
glSelectBuffer(BUFSIZE, selectBuf);
glRenderMode(GL_SELECT);
glInitNames();
glPushName(0);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix((GLdouble) m_lastMouseX, (GLdouble) (h() - m_lastMouseY),
1.0, 1.0, viewport);
gluOrtho2D(.0, w(), .0, h());
redraw();
glPopMatrix();
glFlush();
hits = glRenderMode(GL_RENDER);
cerr << "hits = " << hits << endl;
i figure that if i can first identify the triangle i clicked on then it should be possible to determine the actual position inside of this triangle. however, it seems that i’m never getting any hits so something must be wrong. someone suggests to comment out the line glRenderMode(GL_SELECT), as it should cause the display of only objects inside the area specified by glPickMatrix, but again it is not happening in my program.
any ideas on what could be wrong? any help would be very very appreciated.
[This message has been edited by wenjamin (edited 11-29-2002).]