我听说可以用NewtCanvasJFX将Jogl集成到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为一个大学项目一起工作,所以如果有人有其他解决方案,我会非常感谢。
发布于 2020-04-04 01:19:11
我不能让它在NewtCanvasJFX上工作,但是我用gljpanel把jogl和javafx结合起来。
所有与jogl相关的东西都在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();
}https://stackoverflow.com/questions/60957894
复制相似问题