Hello Guest

[FIXED] OSX Display.setParent issue with LWJGL 2.9.0

  • 6 Replies
  • 11946 Views
[FIXED] OSX Display.setParent issue with LWJGL 2.9.0
« on: April 22, 2013, 12:32:19 »
Hey,

sorry I didn't find much time to follow this but there is one issue remaining with 2.9.0, the NetBeans Swing windowing system and the heavyweight canvas, it looks like this:



From what I see the coordinates are not coming from the right frame, a (hopefully) easy fix?

Anyway everything else seems to work wonderfully on both Java 1.6 and Java 1.7, thanks a lot for the effort!

Cheers,
Normen
« Last Edit: October 23, 2013, 11:21:51 by kappa »

Re: [BUG] OSX Display.setParent issue with LWJGL 2.9.0
« Reply #1 on: July 04, 2013, 16:31:11 »
I have exactly same issue with my code. Works on Windows flawlessly, but same problem on Mac OS X with Java 7 (I'm not able to test it with 1.6 to see if it's the same).
Here is the SSCCE which shows the bug

Code: [Select]
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.PixelFormat;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

// Must import the lwjgl Display class

public class LwjglTest extends JFrame {

    public LwjglTest() throws LWJGLException {
        this.setSize(500, 200);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        RealtimePanel rtCanvas = new RealtimePanel();
        this.getContentPane().add(rtCanvas, BorderLayout.CENTER);

        JButton btnTest = new JButton("test");
        this.getContentPane().add(btnTest, BorderLayout.WEST);

        JButton btnTest2 = new JButton("next test");
        this.getContentPane().add(btnTest2, BorderLayout.NORTH);

        this.pack();
    }

    public static void main(String args[]) {
        try {
            new LwjglTest();
        } catch (LWJGLException ex) {
            ex.printStackTrace();
        }
    }

    private class RealtimePanel extends JPanel {
        Thread gameThread;
        boolean running = false;
        Canvas canvas;
        boolean resized = false;
        boolean sleeping = false;

        public RealtimePanel() {
            setFocusable(true);
            requestFocus();
            setIgnoreRepaint(true);

            canvas = new Canvas();
            canvas.setIgnoreRepaint(true);

            this.setLayout(new GridLayout());
            this.add(canvas);

            canvas.setFocusable(true);
            canvas.setVisible(true);
            canvas.requestFocus();

            canvas.addComponentListener(new ComponentListener() {
                @Override
                public void componentResized(ComponentEvent e) {
                    synchronized (this) {
                        resized = true;
                    }
                }

                @Override
                public void componentMoved(ComponentEvent e) {
                    synchronized (this) {
                        resized = true;
                    }
                }

                @Override
                public void componentShown(ComponentEvent e) {
                }

                @Override
                public void componentHidden(ComponentEvent e) {
                }
            });
        }

        @Override
        public void addNotify() {
            super.addNotify();
            startLWJGL();
        }

        public void startLWJGL() {
            if (gameThread != null) {
                return;
            }

            gameThread = new Thread() {
                @Override
                public void run() {
                    setRunning(true);

                    try {
                        Display.setParent(canvas);
                        Display.create(new PixelFormat().withBitsPerPixel(32).withDepthBits(24).withStencilBits(8));
                    } catch (LWJGLException e) {
                        e.printStackTrace();
                    }
                    gameLoop();
                }
            };
            gameThread.setName("rendering");
            gameThread.start();
        }

        private void stopLWJGL() {
            running = false;
            try {
                gameThread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        protected void initGL() {
            GL11.glMatrixMode(GL11.GL_PROJECTION);
            GL11.glLoadIdentity();
            GL11.glOrtho(0, 800, 0, 600, 1, -1);
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
        }

        public boolean isRunning() {
            synchronized (this) {
                return running;
            }
        }

        public void setRunning(boolean value) {
            synchronized (this) {
                this.running = value;
            }
        }

        public void setSleeping(boolean sleeping) {
            {
                this.sleeping = sleeping;
            }
        }

        public void gameLoop() {
            while (running) {

                // Clear the screen and depth buffer
                GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

                // set the color of the quad (R,G,B,A)
                GL11.glColor3f(0.5f,0.5f,1.0f);

                // draw quad
                GL11.glBegin(GL11.GL_QUADS);
                GL11.glVertex2f(100,100);
                GL11.glVertex2f(100+200,100);
                GL11.glVertex2f(100+200,100+200);
                GL11.glVertex2f(100,100+200);
                GL11.glEnd();

                if (sleeping) {
                    try {
                        Thread.sleep(16);
                    } catch (InterruptedException ex) {
                        ex.printStackTrace();
                    }
                    Display.sync(15);
                    Display.update();

                } else {
                    Display.sync(45);
                    Display.update();
                }
            }

            Display.destroy();
            System.out.println("GL destroyed");
        }

        public void destroyRT() {
            stopLWJGL();
        }
    }
}

Check attachments for screenshots..

*

Offline kappa

  • *****
  • 1319
Re: [BUG] OSX Display.setParent issue with LWJGL 2.9.0
« Reply #2 on: July 04, 2013, 16:38:26 »
oh nice, thanks for the test case, was having difficulty reproducing and isolating the problem with the JME code base, but the standalone test case should be helpful.

Re: [BUG] OSX Display.setParent issue with LWJGL 2.9.0
« Reply #3 on: July 04, 2013, 17:09:24 »
Thanks! I would fix that and post pull request, but I'm not familiar with native Mac OS X programming.. Anyway, in https://github.com/LWJGL/lwjgl/blob/master/src/java/org/lwjgl/opengl/MacOSXDisplay.java seems to be the obvious issue (sorry I'm not able to narrow it more in native code)

Code: [Select]
public void reshape(int x, int y, int width, int height) {
  //if (native_mode) {
  //    nResizeWindow(window, x, y, width, height);
  //}
}

Re: [BUG] OSX Display.setParent issue with LWJGL 2.9.0
« Reply #4 on: July 09, 2013, 15:31:39 »
Any idea of when this issue will be fixed ?

Re: [BUG] OSX Display.setParent issue with LWJGL 2.9.0
« Reply #5 on: August 08, 2013, 08:51:43 »
Hey guys, any news about this issue? I've tried to narrow it down, but with no luck..  :-\

*

Offline kappa

  • *****
  • 1319
Re: [BUG] OSX Display.setParent issue with LWJGL 2.9.0
« Reply #6 on: October 23, 2013, 11:21:04 »
This should be fixed in the latest nightly builds of LWJGL.

@Guro thanks for the test case, really helps in quickly debugging the issue.