MouseListeners on AWTGLCanvas not triggering events

Started by emzic, July 23, 2010, 12:07:19

Previous topic - Next topic

emzic

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!

kappa

Instead of AWTGLCanvas you could use LWJGL Display.setParent(). With Display.setParent you can just use LWJGL's normal Keyboard and Mouse classes

info

kappa

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.

kappa

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 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.

kappa

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.

Kai

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);
    }

broumbroum