Re: 2D Picking with Jogl
Posted by sara on Sep 26, 2012; 11:26pm
URL: https://forum.jogamp.org/2D-Picking-with-Jogl-tp2594712p4026278.html
Hi,
unfortunately gluProject did not solve my problem when I zoom in or zoom out the window,
So I wanna use picking code, but I do not know how to choose the values of glOrtho , I use the width and height but it did not work or other values did not work correctly ,this is my code?
public void pick(GL gl) {
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.glPushMatrix();
gl.glLoadIdentity();
glu.gluPickMatrix((double) pickPoint.x,
(double) ( viewport[3] -pickPoint.y),
5.0, 5.0, viewport, 0);
gl.glOrtho(0.0, wid, 0.0,hi, -0.5, 2.5);
drawRects(gl, GL.GL_SELECT);
gl.glPopMatrix();
gl.glFlush();
hits = gl.glRenderMode(GL.GL_RENDER);
selectBuffer.get(selectBuf);
processHits(hits, selectBuf);
}
I have to present this program in Friday, I really do not know how to solve?
Thanks in advance,
Sara