[FIXED] OSX Display.setParent issue with LWJGL 2.9.0

Started by normen, April 22, 2013, 12:32:19

Previous topic - Next topic

normen

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

Guro

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

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

kappa

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.

Guro

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)

public void reshape(int x, int y, int width, int height) {
  //if (native_mode) {
  //    nResizeWindow(window, x, y, width, height);
  //}
}

fabsradiorossi


Guro

Hey guys, any news about this issue? I've tried to narrow it down, but with no luck..  :-\

kappa

This should be fixed in the latest nightly builds of LWJGL.

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