Please, give me working sample of selection!
My code is:
public void mouseClicked(MouseEvent e) {
System.out.print(glEngine.doSelect(e.getPoint().x, e.getPoint().y));
}
…
public int doSelect(int x, int y) {
float selectionRadius = 7f;
int hits;
int nearestNum;
float nearestRo;
int[] selectBuf = new int[1024];
int vp[] = new int[4];
int width = camera.getWidth();
int height = camera.getHeight();
gl.glViewport(0, 0, width, height);
gl.glGetIntegerv(GL.GL_VIEWPORT, vp);
vp[0] = 0;
vp[1] = 0;
vp[2] = camera.getWidth();
vp[3] = camera.getHeight();
gl.glSelectBuffer(1024, selectBuf);
gl.glRenderMode(GL.GL_SELECT);
gl.glInitNames();
gl.glPushName(0);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPickMatrix(x, camera.getHeight() - y, selectionRadius,
selectionRadius, vp);
camera.applyProjection();
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
camera.applyView();
render(GL.GL_SELECT);
gl.glFlush();
hits = gl.glRenderMode(GL.GL_RENDER);
...... // HITS ARE ALWAYS 0!!!
}