Jogl和JavaFX

问题描述 投票:0回答:1

我听说有可能将Jogl与NewtCanvasJFX集成到JavaFX中,但是我无法使其正常工作。我尝试过类似的方法。

@Override
public void start(Stage primaryStage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
    primaryStage.setTitle("JavaFX Jogl");
    primaryStage.setScene(new Scene(root, 300, 275));
    primaryStage.show();

    //init Canvas
    final GLProfile glProfile = GLProfile.getDefault();
    final GLCapabilities capabilities = new GLCapabilities(glProfile);

    GLWindow glWindow = GLWindow.create(capabilities);

    NewtCanvasJFX glPanel = new NewtCanvasJFX(glWindow);
    glPanel.setWidth(300);
    glPanel.setHeight(300);

    StackPane openGLPane = new StackPane();
    openGLPane.getChildren().add(glPanel);

    glWindow.addGLEventListener(this);
}

我只需要让jogl和Javafx一起为一个大学项目工作,所以如果有人有其他解决方案,我将非常感谢他们。

java opengl javafx jogl
1个回答
0
投票

我无法将其与NewtCanvasJFX配合使用,但我使用gljpanel结合了jogl和javafx。

重要的是,所有与慢跑相关的内容都在SwingUtilities.invokeLater内部,否则将无法呈现任何内容。您可以只使用画布添加gleventlistener。

@Override
public void start(Stage primaryStage) throws Exception{ 
    root = new StackPane();

    final GLProfile glProfile = GLProfile.getDefault();
    final GLCapabilities capabilities = new GLCapabilities(glProfile);

    canvas = new GLJPanel(capabilities);

    swingNode = new SwingNode();

    root.getChildren().add(swingNode);

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            swingNode.setContent(canvas);
            //jogl stuff here           
        }
    });


    primaryStage.setTitle("JavaFX OpenGL");
    primaryStage.setScene(new Scene(root, 1920, 1080));
    primaryStage.show();         
}
© www.soinside.com 2019 - 2024. All rights reserved.