brandonborkholder / glg2d

Graphics2D wrapper for JOGL
77 stars 31 forks source link

Full-Screen Exclusive Mode API - Black Screen #24

Closed SimonH89 closed 10 years ago

SimonH89 commented 10 years ago

Hello, I have an issue using the glg2d wrapper with the java full-screen exclusive mode API. Independet of which display mode I set I'm always getting a black screen. When I don't use the wrapper everything works properly. Here is my test source code:

import org.jogamp.glg2d.GLG2DCanvas;

import javax.swing.*;
import java.awt.*;

public class Fullscreen {

    private static GraphicsDevice device;
    private static JFrame frame;

    public static void main(String[] args) {
        GraphicsEnvironment gsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
        device = gsEnvironment.getDefaultScreenDevice();

        frame = new JFrame();
        frame.setUndecorated(true);
        frame.setIgnoreRepaint(true);
        frame.setResizable(false);

        JComponent canvas = new GLG2DCanvas(new MyRenderPane());
//        JComponent canvas = new MyRenderPane();
        canvas.setSize(new Dimension(1920, 1080));
        frame.setContentPane(canvas);
        frame.setLayout(null);

        device.setFullScreenWindow(frame);
        device.setDisplayMode(new DisplayMode(1920, 1080, 32, DisplayMode.REFRESH_RATE_UNKNOWN));

        frame.repaint();
    }

    private static class MyRenderPane extends JComponent {

        @Override
        public void paintComponent(Graphics g) {
            System.out.println("Drawing...");
            g.setColor(Color.BLUE);
            g.fillRect(0, 0, 200, 200);
        }
    }
}

What I noticed is that the paintComponent method of my JComponent isn't called even though I call repaint on my JFrame. There is no output ("Drawing...") to System.out.

Sorry if i missed somthing, but I couldn't find any information on how glg2d behaves with that API. Is there anything special I need to take care of or is the API not supported yet?

SimonH89 commented 10 years ago

I managed to get full-screen mode to work by myself. There are some issues I needed to take care of:

  1. It seems a null layout manager does not work with the GLG2DCanvas. After using the default layout manager the paintComponent method was called properly. But still the screen remained black.
  2. According to this website - http://opengl.j3d.org/faq/jogl_basics.html - it is necessary to disable DirectDraw usage on a Windows system, to get rendering working in full-screen mode. Therefore the system property -Dsun.java2d.noddraw=true has to be set.

Here is my finally working code:

import org.jogamp.glg2d.GLG2DCanvas;

import javax.swing.*;
import java.awt.*;

public class Fullscreen {

    private static GraphicsDevice device;
    private static JFrame frame;

    private static Dimension resolution = new Dimension(1920, 1080);

    public static void main(String[] args) {
        System.setProperty("sun.java2d.noddraw", "true");

        GraphicsEnvironment gsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
        device = gsEnvironment.getDefaultScreenDevice();

        frame = new JFrame();
        frame.setUndecorated(true);
        frame.setIgnoreRepaint(true);
        frame.setResizable(false);

        JComponent canvas = new GLG2DCanvas(new MyRenderPane());
        canvas.setPreferredSize(resolution);
        frame.setContentPane(canvas);
        frame.pack();

        device.setFullScreenWindow(frame);
        device.setDisplayMode(new DisplayMode(resolution.width, resolution.height, 32, DisplayMode.REFRESH_RATE_UNKNOWN));

        frame.repaint();
    }

    private static class MyRenderPane extends JComponent {

        @Override
        public void paintComponent(Graphics g) {
            System.out.println("Drawing...");
            g.setColor(Color.BLUE);
            g.fillRect(0, 0, 200, 200);
        }
    }
}