PDA

View Full Version : select/pick object



Irena
04-08-2010, 06:14 PM
Hi,
I try to choose the object clicked.By in hits get the total number of object drawn:


glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if(m_selectionFlag)
{
glGetIntegerv(GL_VIEWPORT, viewport);
glSelectBuffer(512, buffer);// Tell OpenGL To Use Our Array For
Selection

(void) glRenderMode(GL_SELECT);


glInitNames(); // Initializes The Name Stack
glPushName(0); // Push 0 (At Least One Entry) Onto The Stack


glMatrixMode(GL_PROJECTION); // Selects The Projection Matrix
glPushMatrix(); // Push The Projection Matrix
glLoadIdentity();
gluPickMatrix((GLdouble) m_mouseX, (GLdouble) (viewport[3]-
m_mouseY), 1.0f, 1.0f, viewport);
}
glMatrixMode(GL_PROJECTION);


glLoadIdentity();
glFrustum(left,right,bottom,top,0.9,2*diam + 2);
glMatrixMode(GL_MODELVIEW);


glLoadIdentity();


GLfloat LightPosition1[]= { 0.0f, 0.0f, 0.0f, 1.0f };
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition1); //stick the light to
the viewer
gluLookAt (0.0,0.0,m_modelsCompainer->getCenter()[2]+diam + 1,
m_modelsCompainer->getCenter()[0],m_modelsCompainer->getCenter()
[1],m_modelsCompainer->getCenter()[2],0.0, 1.0, 0.0);
Draw();
if(m_selectionFlag)
{
glMatrixMode(GL_PROJECTION); glPopMatrix(); glFlush();
//glMatrixMode(GL_MODELVIEW);
hits=glRenderMode(GL_RENDER);
processHits(hits,buffer);



}


may be someone can see the problem thanks!!!