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

查看:701
本文介绍了如何在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 。
这个特性可能不会包含在JavaFX通用可用性版本中,直到最初的Java 8版本发布后的下一个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).

第三方OpenGL / JavaFX集成

您无需等待这么长时间才能开始集成JavaFX和OpenGL。启动实现所需的所有源代码都在 OpenJFX存储库中打开,所以你可以尝试构建该代码与 lwjgl jogl

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.

当开发人员开始使用现有的Java封装器与OpenGL apis进行JavaFX集成时,这个答案将会过时。一些开发人员已经开始这样的工作 - 运行谷歌搜索 lwjgl javafx jogl 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.

最简单的集成可能是让第三方库渲染到屏幕外缓冲区,然后将像素从缓冲区传输到JavaFX WritableImage Canvas ,根据需要将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功能的代码示例进行了描述 - jfx wiki

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 Viewer项目 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引擎有一个开关,允许你使用JavaFX和它的3D功能来自JavaScript ,因此如果您愿意,可以使用其他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天全站免登陆