Reply – Re: How to refer GL context in AWT Mouse Event
Your Name
or Cancel
In Reply To
Re: How to refer GL context in AWT Mouse Event
— by n.j. n.j.
I am very sorry for me too late.
I'd been in hospital cause of my stomach ulcer.

code skel is

public class MyPanel extends GLJPanel implements GLEventListener, MouseListener {
    MouseEvent mouseEvent = null;
    public void mousePressed(MouseEvent e) {
        if(SwingUtilities.isLeftMouseButton(e)) {
            mouseEvent = e;
    public void display(GLAutoDrawable arg0) {
        GL2 gl2 = arg0.getGL().getGL2();
        if (mouseEvent != null) {
            pickup(mouseEvent, gl2, glu);
            mouseEvent = null;
        } else {
    private void pickup(MouseEvent e, GL2 gl, GLUgl2 glu) {
        int x = e.getX();
        int y = e.getY();
        DoubleBuffer model = DoubleBuffer.allocate(16);
        DoubleBuffer proj = DoubleBuffer.allocate(16);
        IntBuffer view = IntBuffer.allocate(4);
        gl.glGetDoublev(GL2.GL_MODELVIEW_MATRIX, model);
        gl.glGetDoublev(GL2.GL_PORJECTION_MATRIX, proj);
        gl.glGetIntegerv(GL2.GL_VIEWPORT, view);
       DoubleBuffer loc = DoubleBuffer.allocate(3);
       FloatBuffer z = FloatBuffer.allocate(1);
       gl.glReadPixels(x, view.get(3)-y-1, 1, 1, GL2.GL_DEPTH_COMPONENT, GL2.GL_FLOAT, z);
       glu.gluUnProject(x, view.get(3)-y-1, z.get(0), model, proj, view, loc);
       DisplayCompartment selected = getDisplayCompartment(loc.get(0), loc.get(1), loc.get(2));
       if (selected != null) {

I got a problem using Mac Book Pro.
As a local coordinate leaves the starting point,
the return Global Coord is differ.
Another mac, Mac Book Air and Mini I'd tested,
the problem does not occur.
So, the way to unproject I'd written could be doubtful, I thought.

I should be very much obliged if you teach me good solution method.