Animator and picking

Hello,

I’m trying to implement picking in a Jogl chess game.
My problem is that picking an object is like throwing a coin : sometimes I hit it and get the names I put on the name stack and sometimes not, although I’m clicking on the same spot.

I’m using the following code in my display mode :

public void display(GLDrawable glDrawable) {
GL myGL = glDrawable.getGL();
GLU myGLU = glDrawable.getGLU();

 if (selectMode) {
   myGL.glGetIntegerv(GL.GL_VIEWPORT, viewport);
   selectBuf = BufferUtils.newIntBuffer(BUFSIZE); 
   myGL.glSelectBuffer (BUFSIZE, selectBuf);
   myGL.glRenderMode(GL.GL_SELECT);
   myGL.glInitNames();
   myGL.glPushName(0);
   myGL.glMatrixMode (GL.GL_PROJECTION);
   myGL.glPushMatrix();
     myGL.glLoadIdentity();
     myGLU.gluPickMatrix (mouseX, viewport[3] - mouseY, 10, 10, viewport);
     myGLU.gluPerspective(60.0, viewport[2]/(float)viewport[3], 0.2, 60.0);
 }

 myGL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
      
 myGL.glMatrixMode(GL.GL_MODELVIEW);
 myGL.glLoadIdentity();
      
 myGL.glTranslatef(0.0f, 0.0f, -dist);

 myGL.glRotatef(angleX, 1.0f, 0.0f, 0.0f);
 myGL.glRotatef(angleZ, 0.0f, 0.0f, 1.0f);
           
 /*** draw the chessboard and the pieces ***/
 myGL.glFlush();
      
 if (selectMode) {
     selectMode=false;
     myGL.glMatrixMode (GL.GL_PROJECTION);
   myGL.glPopMatrix();  
   myGL.glFlush();
   
   hits = myGL.glRenderMode(GL.GL_RENDER);
   processHits(hits, selectBuf);
 }

}

Is it possible, that glFlush() makes problems because I’m using the Animator class?
I don’t no, how the Animator class really works.

Oliver

After testing a while I found out that this problem only occurs on Windows98 .
If I start my program with Linux, I have always a hit when clicking on an object, although I’m using the same Jogl version and the same graphic drivers (nvidia) on both Systems. ???

Why not use gluUnProject instead? It works all the time for me on all systems :slight_smile:

Not necessary, I’ve found the error. :wink:

It was not very clever to check the variable ‘selectMode’ two times in the display method while changing its state when pressing a mouse button.
You have to be very carefully if you are programming with threads :o

Oliver