0
\$\begingroup\$

I am working on a game engine.

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class Main {

    public static void main(String[] args) {
        
        System.setProperty("sun.java2d.opengl", "true");
        
        SwingUtilities.invokeLater(() -> {
            
            Dimension size = new Dimension(800, 600);
//          Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
            
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setTitle("MRE");
            frame.setUndecorated(true);
            frame.setSize(size);
            frame.setVisible(true);
            
            JPanel panel = new JPanel();
            panel.setSize(size);
            panel.setBackground(Color.BLUE);
            frame.add(panel);
        });
    }
}

When you run this code you should see an undecorated frame with a blue JPanel. However if you switch the size variable with the commented one the whole screen turns black. When I disabled sun.java2d.openglit worked, but I want to draw all graphics using the GPU and not the CPU. Debugging it, I noticed the issue is only when the size is the screen size (1280, 1024), The dimensions 1280, 1025 work fine

\$\endgroup\$
4
  • \$\begingroup\$ What values do you get back from Toolkit.getDefaultToolkit().getScreenSize()? Have you tried logging them to a console/log file or inspecting them in a debugger with a breakpoint? \$\endgroup\$
    – DMGregory
    Commented Mar 27 at 14:48
  • \$\begingroup\$ @DMGregory java.awt.Dimension[width=1280,height=1024] I would like to know if the issue is for me only or it is a common issue \$\endgroup\$ Commented Mar 27 at 14:49
  • \$\begingroup\$ Why are you adding the JPanel after you've called setVisible(true) on the JFrame? Doing this means that the GUI has already been rendered when the panel is added. Better to call pack() and setVisible(true) on the JFrame after all components have been added. \$\endgroup\$ Commented Mar 27 at 16:26
  • \$\begingroup\$ @HovercraftFullOfEels still didnt fix the issue :/ \$\endgroup\$ Commented Mar 27 at 16:55

0

You must log in to answer this question.

Browse other questions tagged .