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