Integrating javafx ui into custom (jogl based) OpenGL application
swpalmer at gmail.com
Sat Mar 2 17:19:49 PST 2013
On 2013-03-02, at 3:46 PM, Christoph Caks <ccaks at bestsolution.at> wrote:
> Am 02.03.2013 19:56, schrieb Scott Palmer:
>> On 2013-03-02, at 8:09 AM, Herve Girod <herve.girod at gmail.com> wrote:
>>>> I'm developing a OpenGL based 3d application and instead of writing my
>>>> own ui code I'd like to reuse javafx for the ui part.
>>>> Since getting an OpenGL context from JavaFX seems to be very complicated
>>>> (as discussed here) i thought about a different approach.
>>>> What if javafx could reuse my rendering context.
>>>> I'm thinking of implementing a custom prism backend which renders within
>>>> my application context, after my content was rendered.
>>>> As far as i know is the prism api is an internal implementation detail,
>>>> but it may be possible to ignore changes to it by bundling a specific
>>>> jre version with the application.
>>>> I have not yet digged into prism code but I like to hear your thoughts
>>>> about this approach.
>>>> greetings Christoph
>>> We also would like to integrate a JavaFX UI in an external OpenGL context.
>>> We already do it with regular Swing by leveraging JOGL and another
>>> OpenGL-AWT geom bridge library in our Open source project (
>>> http://sourceforge.net/projects/j661/), but it's not so simple to to it
>>> well. It would be greate to be able to make JavaFX to work "easily" with
>>> other applications which also use OpenGL.
>>> Our use case is integrating Java graphics on top of an external context
>>> created by apps such as a flight simulator terrain rendering for example.
>>> We could also do it in Java of course, but often you have to use an
>>> existing OpenGL renderer for that.
>>> However for information it's not necessary to change the JDK to do this in
>>> Swing, even if it is not simple as I said.
>> I wonder if something as simple as using two windows would work. Your custom OpenGL window beneath a mostly transparent but otherwise ordinary JavaFX Stage. The issue of course is keeping the two windows paired up. That's one reason that I've been pushing for access to native window handles (via JNI-only so there are no security concerns). It would be awesome if we had the ability to make a window via native code that used our JavaFX window as it's parent.
>> It *seems* like a simple thing to do, but it opens up a world of possibilities.
> In windows this would mean you have an directx javafx stage on top of an opengl based application - i have no idea how those two affect each other in terms of performance since they need to share a single graphics card.
I don't have a good idea either, but it should be easy to find out.
I personally don't know why Java, being a cross platform system, would bother with DirectX when OpenGL is already cross-platform.
I've heard that the DirectX (Direct3D) drivers are usually more polished on Windows… sadly choosing Direct3D leads to a feedback cycle that ensures that will always be the case.
(Reminds me of this: http://blog.wolfire.com/2010/01/Why-you-should-use-OpenGL-and-not-DirectX )
> i don't like the idea to use an additional graphics system like directx for rendering the ui of an opengl based application.
> I'm trying to write my own jogl based prism pipeline and made some progress: i already 'injected' my pipline and got some things running, but i'm still trying to render a simple rectangle.
> As far as i know oracles first es2 implementation was also jogl based - its a pity that this code is not opensource, it would speed things up -.-
Presumably you can look at the Linux and Mac versions that are open sourced, since they would have to use OpenGL for hardware acceleration.
> And even if i succeed in implementing a working pipeline - i still face some problems:
> - i'll have to keep it compatible with changes in the internal prism api
> - and the only way (i found so far) to inject it, is to place a jar into the ext folder of the jre
> - also i have no idea about legal issues - is it for example allowed to bundle a patched jre with my application? (patched = additional jars in ext folder)
If you are basing this on Open-JFX you just have to comply with the open source license. I am not a lawyer, but I think that means you can have a hacked up Java, as long as you don't call it Java. (Since you would not have gone through the process of passing compatibility tests and all that stuff.)
More information about the openjfx-dev