I'm creating a simple (for now) model viewer applet in Java using JOGL.
What I would like to get working first is an universe with several simple objects (cubes etc), be able to rotate/zoom/pan on the universe and be able to select single objects.
I've got the simple universe setup, only mouseclicks are not hitting any objects. Any pointers what I'm doing wrong?
These are relevant (I think) snippets for my applet.
Code :public void display(GLAutoDrawable drawable) { // .. drawCubes(GL.GL_RENDER); gl.glFlush(); // manual using GL_QUADS }Code :// MouseMotionListener interface implemented public void mouseDragged(MouseEvent e) { // angle (float) and axis (int[3]) are calculated gl.glRotatef(angle, axis[0], axis[1], axis[2]);Code :public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); // Orthogonal projection, translated for better fitting onscreen gl.glOrtho(left, right, bottom, top, 0.01f, 1000.0f); gl.glTranslatef(0.0f, 0.0f, -500.0f); }
And now the not-working part:
Code :// Called on each mouseClicked() event. private void pickRects(GL gl) { final int BUFSIZE = 512; int[] selectBuf = new int[BUFSIZE]; IntBuffer selectBuffer = BufferUtil.newIntBuffer(BUFSIZE); int hits; int viewport[] = new int[4]; gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0); gl.glSelectBuffer(BUFSIZE, selectBuffer); gl.glRenderMode(GL.GL_SELECT); gl.glInitNames(); gl.glPushName(-1); gl.glMatrixMode(GL.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); // pickPoint.xy (ints) is set correctly on each mouseclick glu.gluPickMatrix((double) pickPoint.x, (double) (viewport[3] - pickPoint.y), 5.0, 5.0, viewport, 0); drawCubes(GL.GL_SELECT); // now glLoadName(x) is used gl.glPopMatrix(); gl.glFlush(); hits = gl.glRenderMode(GL.GL_RENDER); // hits is always 0 in my testcase, why? selectBuffer.get(selectBuf); proces****s(hits, selectBuf); }
Any ideas what's going wrong?
The mouseClicked event is registering fine, the x,y mouse coordinates are correct too.
It's just that I get no hits at all in GL_SELECT mode.