如何在 JavaFX 中使用 OpenGL? [英] How to use OpenGL in JavaFX?

查看:27
本文介绍了如何在 JavaFX 中使用 OpenGL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个非常简单的 Java 3D 编辑器(用于实验).我知道基本的 JavaFX 用法,并且我知道足够的 OpenGL 知识.但我所有的 OpenGL 经验都来自于使用 C/C++.

I want to write a very simple Java 3D editor(for experiment). I know the basic JavaFX usage, and I know enough OpenGL knowledge. But all my OpenGL experience is from working with C/C++.

我可以在 JavaFx 应用程序中制作一个画布"并在其上映射 OpenGL 视口吗?

Could I make a 'canvas' in JavaFx application and map OpenGL viewport on it?

推荐答案

JavaFX 在内部可以使用 OpenGL 作为渲染管道,因此需要注意两者之间的集成以避免冲突.

Internally, JavaFX can use OpenGL as a rendering pipeline, so some care on integration between the two is required to avoid conflicts.

JavaFX 中的 OpenGLNode

Richard Bair,JavaFX 团队负责人发布在 openjfx开发邮件列表:

Richard Bair, JavaFX team lead posted on the openjfx development mailing list:

我希望为 8 更新完成的一件事(例如)是有一个 OpenGLNode 或 NativeSurfaceNode 或类似的东西,这样如果你正在做你自己的 D3D/OpenGL 你可以有一种方法来发送那些原始命令下至显卡,但仍将您的节点合成在场景图中.

One thing I want to see done (for example) for the 8 update is to have an OpenGLNode or NativeSurfaceNode or something along those lines so that if you are doing your own D3D / OpenGL you can have a way to send those raw commands down to the graphics card but still have your node composited in the scene graph.

因此,未来的 JavaFX 版本更新可能会包含 OpenGLNode.在最初的 Java 8 发布之后的下一个 JavaFX 功能发布之前,这样的功能可能不会包含在 JavaFX 通用发布版本中(我的猜测是大约在 2014 年 9 月发布).

So a future JavaFX release update might include an OpenGLNode. Such a feature would probably not see inclusion in a JavaFX general availability release until the next JavaFX feature release after the initial Java 8 release (my guess is that would put it at about September 2014).

第 3 方 OpenGL/JavaFX 集成

您无需等待很长时间即可开始集成 JavaFX 和 OpenGL.启动实现所需的所有源代码都在 OpenJFX 存储库 中打开,因此您可以尝试使用诸如 lwjgljogl.

You don't need to wait so long to start integrating JavaFX and OpenGL. All of the required source code to start an implementation is open in the OpenJFX repository, so you could try building a custom integration of that code with a library such as lwjgl or jogl.

随着开发人员开始将 JavaFX 与现有的 OpenGL apis 包装器集成,此答案将过时.一些开发人员已经开始了这样的工作 - 运行谷歌搜索 lwjgl javafxjogl javafx 以了解当前的集成项目及其状态.

This answer will get dated as developers start performing integrations of JavaFX with existing Java wrappers for OpenGL apis. Some developers have started such work already - run a google search of lwjgl javafx or jogl javafx to find out about current integration projects and their status.

最简单的集成可能是将第 3 方库渲染到屏幕外缓冲区,然后将像素从缓冲区传输到 JavaFX WritableImageCanvas 用于将 OpenGL 渲染的图形合成到 JavaFX 场景图中.

The simplest integration is probably to have a 3rd party library render to an off screen buffer then transfer the pixels from the buffer to a JavaFX WritableImage or Canvas as required to get the OpenGL rendered graphics composited into the JavaFX scene graph.

JavaFX 3D API 替代方案

JavaFX 拥有自己的轻量级 3D api,能够将 phong 着色 3d 模型合成到 JavaFX 场景图中.JavaFX 3D api 不会提供完整的 OpenGL api 集成的所有功能,但是使用 JavaFX 3D api 相对简单.一个描述,以及 Java 8 中的 3D 特性的代码示例位于 open-jfx维基.

JavaFX has its own lightweight 3D api that provides the ability to composite phong shaded 3d models into the JavaFX scene graph. The JavaFX 3D api is not going to provide all the power of a full OpenGL api integration, however using the JavaFX 3D api is relatively simple. A description, with code examples of the 3D features in Java 8 is on the open-jfx wiki.

Interactive Mesh 提供了一个免费的JavaFX 3D 模型导入器,它允许您非常只需将复杂的着色和纹理 3D 模型带入 JavaFX 场景图中即可.

Interactive Mesh provides a free 3D model importer for JavaFX, that allows you to very simply bring complex shaded and textured 3D models into a JavaFX scene graph.

有一个 3D 查看器openjfx 存储库中的项目,您可以将其分叉以创建您提议的基础基于 JavaFX 的 3D 编辑器.

There is a 3D Viewer project in the openjfx repository that you could fork to create a basis for your proposed JavaFX based 3D editor.

nashorn JavaScript 引擎有一个开关,允许您从 JavaScript 使用 JavaFX 及其 3D 功能,因此您可以根据需要使用其他 jvm 语言来访问 JavaFX 3D 功能.

The nashorn JavaScript engine has a switch that allows you to use JavaFX and its 3D features from JavaScript, so you can use alternative jvm languages to access JavaFX 3D features if you prefer.

这篇关于如何在 JavaFX 中使用 OpenGL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆