I cant get picking working in my application. The Hit-Value returns all Objects on screen.
Here some excerpts from my code:
void OglCode::draw(){
glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glShadeModel (GL_SMOOTH);
glLightfv( GL_LIGHT0, GL_POSITION, g_LightPosition);
glLightfv( GL_LIGHT0, GL_DIFFUSE, g_LightDiffuse);
glLightfv( GL_LIGHT0, GL_AMBIENT, g_LightAmbient);
glLightfv( GL_LIGHT1, GL_POSITION,g1_LightPosition);
glLightfv( GL_LIGHT1, GL_DIFFUSE, g1_LightDiffuse);
glLightfv( GL_LIGHT1, GL_AMBIENT, g1_LightAmbient);
glPushMatrix();
glRotatef(view_rotx, 1.0f, 0.0f,0.0f);
glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);
if(mode == GL_SELECT){
for(int i = 0;i<Listcount;i++){
glPushMatrix();
glLoadName(i);
glCallList(i);
glPopMatrix();
}
}
else{
drawCoordinateGizmo();
drawGrid();
for(int i =0;i<POPSIZE;i++){
drawApex(Population[i]);
}
for(int i = 0;i<Listcount;i++){
glPushMatrix();
glCallList(i);
glPopMatrix();
}
}
glPopMatrix();
this->swapBuffers();
}
void OglCode::processHits(int x, int y){
const int buffsize= POPSIZE;
GLuint select_buf[buffsize]; //selection buffer
int hits; //number of hits
glSelectBuffer(buffsize, select_buf);
//set up view matrix here - ie do whatever transformations
glRenderMode(GL_SELECT);
glInitNames();
glPushName(0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
gluPickMatrix((GLdouble)mousex,
(GLdouble)(viewport[3]-mousey),
1, 1,
viewport);
glFrustum(-verhaeltnis, verhaeltnis, -1.0, 1.0, 4.0, 15.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
this->swapBuffers();
draw();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glLoadIdentity();
glFlush(); //flush the pipeline
hits = glRenderMode(GL_RENDER); //switch back to RENDER mode
mode = GL_RENDER;
}
Maybe i should mention that i use QT and QGLWidget…