OpenGL Java2D Graphics Acceleration Doesn't Work

I want to use Swing along with Java2D OpenGL Graphics Acceleration. However, this does not work.

I answered this myself, as I have been looking for a solution for some time.

Here is my code:

import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class OpenGLTest {
    public static void main(String[] args) throws ClassNotFoundException,
            InstantiationException, IllegalAccessException,
            UnsupportedLookAndFeelException {
        // set system look and feel
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

        // activate opengl
        System.setProperty("sun.java2d.opengl", "true");

        // create and show the GUI in the event dispatch thread
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                createAndShowGUI();
            }
        });
    }

    private static void createAndShowGUI() {
        JFrame frame = new JFrame();
        frame.setTitle("OpenGL Test");
        frame.setSize(400, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}
+1
source share
1 answer

Problem

The problem with the above code is that it interacts with the Swing class before the property is "sun.java2d.opengl"set to "true". Customizing the look is already considered such an interaction.

Problem check

, "sun.java2d.opengl" "true" "true". Java2D Properties Guide, , Java , OpenGL:

OpenGL pipeline enabled for default config on screen 0

, "true", . , OpenGL .

, .

        // set system look and feel
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

        // activate opengl
        System.setProperty("sun.java2d.opengl", "true");

        // activate opengl
        System.setProperty("sun.java2d.opengl", "True");

        // set system look and feel
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

, , , OpenGL .

+1

Source: https://habr.com/ru/post/1694979/


All Articles