JFrame full screen problem

Hi there,

I make a JOGL program, and when I set the JFrame to full screen mode, every objects I loaded are gone.

In my program, I use a JPanel and add the JPanel to a JFrame using the following code.

    jframe.getContentPane().setLayout( new BorderLayout() );
jframe.getContentPane().add(makeRenderPanel(period), BorderLayout.CENTER);
jframe.addWindowListener(this);

I use the following function to set JFrame to full screen.

public void setFullScreen(DisplayMode displayMode) {
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setUndecorated(true);
frame.setIgnoreRepaint(true);
frame.setResizable(false);
frame.pack();
frame.setVisible(true);

    device.setFullScreenWindow(frame);

    if (displayMode != null &&
        device.isDisplayChangeSupported())
    {
        try {
            device.setDisplayMode(displayMode);
        }
        catch (IllegalArgumentException ex) { }
  
        frame.setSize(displayMode.getWidth(),
            displayMode.getHeight());
    }

    try {
        EventQueue.invokeAndWait(new Runnable() {
            public void run() {
                frame.createBufferStrategy(2);
            }
        });
    }
    catch (InterruptedException ex) {
        // ignore
    }
    catch (InvocationTargetException  ex) {
        // ignore
    }


}

I get quite confused about this problem. Is there anyone who can help me with this?

Thank you very much!

I use the following code to build the JPanel.

private JPanel makeRenderPanel(long period)
// construct the canvas
{
JPanel renderPane = new JPanel();
renderPane.setLayout( new BorderLayout() );
renderPane.setOpaque(false);
renderPane.setPreferredSize( new Dimension(PWIDTH, PHEIGHT));

canvas = makeCanvas(period);
renderPane.add(“Center”, canvas);

canvas.setFocusable(true);
canvas.requestFocus(); // the canvas now has focus, so receives key events

// detect window resizes, and reshape the canvas accordingly
renderPane.addComponentListener( new ComponentAdapter() {
public void componentResized(ComponentEvent evt)
{ Dimension d = evt.getComponent().getSize();
// System.out.println("New size: " + d);
canvas.reshape(d.width, d.height);
} // end of componentResized()
});

return renderPane;
} // end of makeRenderPanel()

private GameCore makeCanvas(long period)
{
// get a configuration suitable for an AWT Canvas (for TourModelsCanvasGL)
GLCapabilities caps = new GLCapabilities();

AWTGraphicsDevice dev = new AWTGraphicsDevice(null);

AWTGraphicsConfiguration awtConfig = (AWTGraphicsConfiguration)GLDrawableFactory.getFactory().chooseGraphicsConfiguration(caps, null, dev);

GraphicsConfiguration config = null;

// GLCanvas glScene = new GLCanvas();

if (awtConfig != null) config = awtConfig.getGraphicsConfiguration();

return new GameCore(period, PWIDTH, PHEIGHT, config, caps);
} // end of makeCanvas()

public void initScreenModel(DisplayMode[] possibleModes) {
screen = new ScreenManager();
DisplayMode displayMode = screen.findFirstCompatibleMode(possibleModes);
screen.setFullScreen(displayMode);

Window window = screen.getFullScreenWindow();
window.setFont(new Font("Dialog", Font.PLAIN, DEFAULT_FONT_SIZE));

// window.setBackground(Color.blue);
//window.setForeground(Color.white);
}

I’m a little unclear as to what your problem is. Is it that textures and vbo’s and display lists are no longer accessible to your program, or is that you’ve previously drawn things onto the window when it wasn’t full screen and then they stop drawing when you switch modes?

Either way you’re probably dealing with a context switch since you’re changing the display properties of the screen so any previous GLContexts that you had created were no longer valid and GLCanvas replaced them behind the scenes with update to date ones. Unless JOGL does something tricky when this happens, this means that you lose everything resident on that context.
I’d recommend not actually calling display(), or starting your animator on your GLEventListener until after your program has successfully entered fullscreen mode.
Also, since your code doesn’t work, instead of having //ignore in your catch blocks, actually print any exceptions that happen so you know if there’s a problem.

Hi lhkbob,

You are correct, and thank you very much!

I solved this problem. I put "initScreenModel(SCREEN_DEFAULT_MODES); " at init() method in the main java class. Then in the main() method, I set the JFrame to visible.

I think the program will first change to full screen mode, then run other methods. And I use setFullScreen(DisplayMode displayMode) and public void initScreenModel(DisplayMode[] possibleModes) to set the full screen mode. These two method can be found here.

I also hope this can help other newcomers of JOGL just like me.

Thanks lhkbob!