LWJGL Forum

Programming => OpenGL => Topic started by: emzic on July 23, 2010, 12:07:19

Title: MouseListeners on AWTGLCanvas not triggering events
Post by: emzic on July 23, 2010, 12:07:19
hi,
i try to add a MouseMotionListener to the AWTGLCanvas, but it seems that no mouseevent are being triggered. is there something special that needs to be taken care of? (it is working on a GLCanvas from jogl)

unfortunately i cannot use the Mouse helperclass from the LWJGL utils.

thanks!
Title: Re: MouseListeners on AWTGLCanvas not triggering events
Post by: kappa on July 23, 2010, 13:22:44
Instead of AWTGLCanvas you could use LWJGL Display.setParent(). With Display.setParent you can just use LWJGL's normal Keyboard and Mouse classes

info (http://lwjgl.org/forum/index.php/topic,3406.msg18859.html#msg18859)
Title: Re: MouseListeners on AWTGLCanvas not triggering events
Post by: kappa on July 23, 2010, 14:56:32
Quote from: emzic on July 23, 2010, 14:33:27
thanks!
actually i do use Display.setParent on my AWTGLCanvas. but now where should i add my mouselisteners if not on the canvas?



oh wait, thats the wrong way to do it, you don't use Display.setParent() & AWTGLCanvas together. You either use AWTGLCanvas or Display.setParent(). Both are different methods of embedding LWJGL with AWT. Display.setParent() is slightly faster then using AWTGLCanvas though.
Title: Re: MouseListeners on AWTGLCanvas not triggering events
Post by: kappa on July 23, 2010, 15:03:38
Quote from: emzic on July 23, 2010, 15:01:05
thanks!

ok so i converted my AWTGLCanvas to a normal java.awt.Canvas, but now i am getting this exception.

org.lwjgl.LWJGLException: Parent.isDisplayable() must be true
   at org.lwjgl.opengl.Display.createWindow(Display.java:310)
   at org.lwjgl.opengl.Display.create(Display.java:855)
   at org.lwjgl.opengl.Display.create(Display.java:783)
   at org.lwjgl.opengl.Display.create(Display.java:764)

This error basically tells you that the canvas is not yet ready and you are attempting to create and stick a Display on it.

if you look at the gearsapplet (http://java-game-lib.svn.sourceforge.net/viewvc/java-game-lib/trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java?revision=3385&view=markup) you will see that the addNotify and removeNotify methods of the canvas are used to create the Dispaly. This will create the Display when the canvas is ready.
Title: Re: MouseListeners on AWTGLCanvas not triggering events
Post by: kappa on July 23, 2010, 16:15:57
well since you are using a Native Display you can just wrap the LWJGL Mouse class to create your own mouse listener. See source code of Slick2D for a nice example on how to do this.
Title: Re: MouseListeners on AWTGLCanvas not triggering events
Post by: Kai on July 29, 2010, 17:41:18
Hi,

I am having no troubles with AWTGLCanvas and mouse listeners. To find out what is going wrong with your code, please first try the following simple test case:

    public static void main(String[] args) throws Exception {
        JFrame frame = new JFrame("Mouse Test");
        AWTGLCanvas canvas = new AWTGLCanvas() {
            protected void paintGL() {
                GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
                try {
                    swapBuffers();
                } catch (LWJGLException e) {
                }
            }
        };
        frame.setSize(200, 200);
        frame.getContentPane().add(canvas);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        canvas.addMouseMotionListener(new MouseMotionListener() {
            public void mouseMoved(MouseEvent e) {
                System.out.println(e);
            }

            public void mouseDragged(MouseEvent e) {
                System.out.println(e);
            }
        });
        frame.setVisible(true);
    }
Title: Re: MouseListeners on AWTGLCanvas not triggering events
Post by: broumbroum on July 29, 2010, 21:02:10
there's a way to disable LWJGL input Mouse and keyboard listeners, http://lwjgl.org/forum/index.php/topic,637.msg4540.html#msg4540 .