18

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++.

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

2

6 Answers 6

18

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

OpenGLNode in JavaFX

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

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.

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).

3rd Party OpenGL/JavaFX integration

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.

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.

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 Alternative

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 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.

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.

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.

Sign up to request clarification or add additional context in comments.

3 Comments

So, almost 1 year has passed... Are there any news about OpenGLNode?
No Sarge, you can try asking on the mailing list linked in the answer.
This is such a desirable addition to JavaFX. Wish this would materialise.
2

You can use the OpenGLFX library, which mixes the previously mentioned JOGL/LWJGL and JavaFX. The code has the best performance available without changing the source code of JavaFX itself.

1 Comment

This could turn out as the best available option of how to do this in JavaFX. The performance is awesome, it's cross platform, Windows/ Linux and potentially MacOS is supported, you can use it with LGWL or JOGL and it offers DirectX support via NV_DX_interop. I use it for my real time video streaming app and despite small issues which the dev is currently working on its working flawlessly. Really one of the best open source libs I found in the past recent years.
1

Yes, by all means, you can use JOGL to achieve effectively everything you could in Java with OpenGL as you can in C/C++.

2 Comments

You sure can use JOGL or LWJGL to use OpenGL from Java, but it is really not that simple to implement it in an existing JavaFX window.
This does not answer the question much. The question asks how, the answer just points in a general direction.
1

PanamaGL allows rendering OpenGL scenes in a JavaFX canvas. It uses recent Oracle FFM API as of JDK19 to bind to OpenGL, which make it extremely simple to build.

Comments

0

DriftFX allows you to render any OpenGL content directly into JavaFX nodes. Direct means that there is no transfer between GPU and main memory. The textures never leave the GPU.

You can access the project on GitHub : DriftFX

Comments

0

You can simply use NewtCanvasJFX available in JOGL >= 2.4.0. I advise you to read my article that explains in details how to mix JOGL with JavaFX/OpenJFX. NewtCanvasJFX acts as a bridge between JOGL NEWT GLWindow used to perform OpenGL rendering and an OpenJFX/JavaFX group that you can add into a Scene, then you add the Scene into the Stage of your OpenJFX/JavaFX Application.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.