[英]Jogl and JavaFX
我聽說可以使用 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 一起為一個大學項目工作,所以如果有人有其他解決方案,我會非常感激他們。
我無法讓它與 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();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.