Jogl and JavaFX

classic Classic list List threaded Threaded
42 messages Options
123
Reply | Threaded
Open this post in threaded view
|

Re: Jogl and JavaFX

Sweck
That't not doing the trick sadly.
Reply | Threaded
Open this post in threaded view
|

Re: Jogl and JavaFX

gouessej
Administrator
In reply to this post by Sven Gothel
Reply | Threaded
Open this post in threaded view
|

Re: Jogl and JavaFX

gouessej
Administrator
In reply to this post by Sweck
Sweck wrote
That't not doing the trick sadly.
I'll give it a try this weekend if I'm neither sick nor too much tired. I have almost no experience with OpenJFX / JavaFX.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Jogl and JavaFX

DamagedTiberius
In reply to this post by Sweck
I overlooked a missing piece in your init method as well. You need to set the view port. Add something along the lines of this to the end of init():
    final GL4 gl = arg0.getGL().getGL2();
    gl.glViewport(0, 0, arg0.getWidth(), arg0.getHeight());

If that doesn't get you going:

  • Take a look at the rest of my init method to see if any of the other differences are significant.
  • Set some breakpoints in your display(), init(), dispose(), and reshape() methods
    • Do all the values of your member variables make sense (i.e. does it look like everything was initialized as expected)?
    • Are any of the methods called when you don't expect them to be?
Reply | Threaded
Open this post in threaded view
|

Re: Jogl and JavaFX

Sven Gothel
Administrator
In reply to this post by gouessej
On 4/2/20 10:18 PM, gouessej [via jogamp] wrote:
> Github is down :s
>
> You can find the unit test here too:
> https://jogamp.org/cgit/jogl.git/tree/src/test/com/jogamp/opengl/test/junit/jogl/javafx/TestNewtCanvasJFXGLn.java
>

I did use jogamp's cgit reference Julien - as I do not promote github neither :)

~Sven
Reply | Threaded
Open this post in threaded view
|

Re: Jogl and JavaFX

Sweck
In reply to this post by gouessej
@gouessej
Thank you very much!

@DamagedTiberius
The viewport gets set in reshape and reshape gets called when the window opens.

The code works fine when I use GLCanvas and a Jframe as I told you before but I tested it with GLJPanel and JFrame and I get the same problem. When I use GLJPanel the object shows for a millisecond and than disappears completely. It has to do something with gljpanel I asume.
Reply | Threaded
Open this post in threaded view
|

Re: Jogl and JavaFX

DamagedTiberius
You also need to call it in init(). JOGL can destroy the context originally created with the window and will call init() again to set things up. Reshape will not be called in that event.
Reply | Threaded
Open this post in threaded view
|

Re: Jogl and JavaFX

Sweck
Okay I got it!

The Objects I wanted to render were not initialized in the swing thread. All OpenGl related stuff is now done in the Swing thread and it works fine.

I thank you all for the help.

I would highly appreciate if anyone still has an idea how to fix this code to work with the newtCanvasFX.

 @Override
        public void start(Stage primaryStage) throws Exception{
            final GLProfile glProfile = GLProfile.getDefault();
            final GLCapabilities capabilities = new GLCapabilities(glProfile);
           
            GLWindow glWindow = GLWindow.create(capabilities);
            glWindow.addGLEventListener(this);

           NewtCanvasJFX canvas= new NewtCanvasJFX(glWindow);

            final FPSAnimator animator = new FPSAnimator(glWindow, 60);
            animator.start();
           
            StackPane root = new StackPane();
            root.getChildren().add(canvas);
           
            primaryStage.setTitle("JavaFX OpenGL");
            primaryStage.setScene(new Scene(root, 300, 275));
            primaryStage.show();
        }
Reply | Threaded
Open this post in threaded view
|

Re: Jogl and JavaFX

gouessej
Administrator
In reply to this post by Sweck
Ok I've just created a tiny non modular project with JOGL, OpenJDK 14 and OpenJFX 14 without Maven as JOGL 2.4.0 isn't on our Maven development repository (I guess?). I've succeeded in running it. I'll move to the very latest RC of JOGL 2.4.0. For the moment, I get this warning:
(java:16048): Gdk-WARNING **: 19:19:25.453: XSetErrorHandler() called with a GDK error trap pushed. Don't do that.

I hope that it's not important.

For others who try to compile in command line, take care of the order of the options, the main class must be the very last thing you mention when you run:
javac --module-path $PATH_TO_FX --add-modules javafx.controls src/main/java/org/jogamp/joglojfx/App.java -d target/classes -cp jogamp-fat.jar
// replace : by ; under Microsoft Windows
java --module-path $PATH_TO_FX --add-modules javafx.controls -cp target/classes:jogamp-fat.jar org.jogamp.joglojfx.App

P.S: Sweck, I'll try to provide a simple example with NewtCanvasJFX, GLEventListener and an Animator (based on Sven's unit test). I really need to have a rest right now. I'll be back soon.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Jogl and JavaFX

Sweck
@gouessej

Thank you, I really appreciate your work!
Reply | Threaded
Open this post in threaded view
|

Re: Jogl and JavaFX

gouessej
Administrator
This is my first attempt:


package org.jogamp.joglojfx;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GL2ES1;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.fixedfunc.GLLightingFunc;
import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
import com.jogamp.newt.NewtFactory;
import com.jogamp.newt.Screen;
import com.jogamp.newt.javafx.NewtCanvasJFX;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.util.Animator;

public class App extends Application {

    @Override
    public void start(Stage stage) {
        Platform.setImplicitExit(false);
        final Group g = new Group();
        Scene scene = new Scene(g, 800, 600);
        stage.setScene(scene);
        stage.show();
        com.jogamp.newt.Display jfxNewtDisplay = NewtFactory.createDisplay(null, false);
        final Screen screen = NewtFactory.createScreen(jfxNewtDisplay, 0);
        final GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
        final GLWindow glWindow1 = GLWindow.create(screen, caps);
        glWindow1.addGLEventListener(new GLEventListener() {
               private float rotateT = 0.0f;
       
               public void init(final GLAutoDrawable drawable) {
                   GL2 gl = drawable.getGL().getGL2();
                           gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
                           gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
                           gl.glClearDepth(1.0f);
                           gl.glEnable(GL.GL_DEPTH_TEST);
                           gl.glDepthFunc(GL.GL_LEQUAL);
                           gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
               }
               public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
                   GL2 gl = drawable.getGL().getGL2();
                           final float aspect = (float) width / (float) height;
                           gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
                           gl.glLoadIdentity();
                           final float fh = 0.5f;
                           final float fw = fh * aspect;
                           gl.glFrustumf(-fw, fw, -fh, fh, 1.0f, 1000.0f);
                           gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
                           gl.glLoadIdentity();
               }
               public void display(final GLAutoDrawable drawable) {
                   final GL2 gl = drawable.getGL().getGL2();
                           gl.glClear(GL.GL_COLOR_BUFFER_BIT);
                           gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
                           gl.glLoadIdentity();
                           gl.glTranslatef(0.0f, 0.0f, -5.0f);
 
                           // rotate about the three axes
                           gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f);
                           gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);
                           gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f);
 
                           // Draw A Quad
                           gl.glBegin(GL2.GL_QUADS);      
                           gl.glColor3f(0.0f, 1.0f, 1.0f);   // set the color of the quad
                           gl.glVertex3f(-1.0f, 1.0f, 0.0f);   // Top Left
                           gl.glVertex3f( 1.0f, 1.0f, 0.0f);   // Top Right
                           gl.glVertex3f( 1.0f,-1.0f, 0.0f);   // Bottom Right
                           gl.glVertex3f(-1.0f,-1.0f, 0.0f);   // Bottom Left
                           // Done Drawing The Quad
                           gl.glEnd();                                                    
 
                           // increasing rotation for the next iteration                  
                           rotateT += 0.2f;
               }
               public void dispose(final GLAutoDrawable drawable) {
               }
            });
        final NewtCanvasJFX glCanvas = new NewtCanvasJFX(glWindow1);
        glCanvas.setWidth(800);
        glCanvas.setHeight(600);
        g.getChildren().add(glCanvas);
        final Animator anim = new Animator(glWindow1);
        anim.start();
    }

    public static void main(String[] args) {
        launch();
    }
}

I obtain the following error message:
Exception in thread "JavaFX Application Thread" com.jogamp.nativewindow.NativeWindowException: Error getting JFX-Thread
        at com.jogamp.nativewindow.javafx.JFXAccessor.getJFXThread(JFXAccessor.java:192)
        at com.jogamp.nativewindow.javafx.JFXAccessor.isJFXThreadOrHasJFXThreadStopped(JFXAccessor.java:217)
        at com.jogamp.nativewindow.javafx.JFXAccessor.runOnJFXThread(JFXAccessor.java:160)
        at com.jogamp.nativewindow.javafx.JFXAccessor.getWindowHandle(JFXAccessor.java:272)
        at com.jogamp.newt.javafx.NewtCanvasJFX.validateNative(NewtCanvasJFX.java:338)
        at com.jogamp.newt.javafx.NewtCanvasJFX.repaintAction(NewtCanvasJFX.java:174)
        at com.jogamp.newt.javafx.NewtCanvasJFX.access$200(NewtCanvasJFX.java:83)
        at com.jogamp.newt.javafx.NewtCanvasJFX$5.changed(NewtCanvasJFX.java:163)
        at com.jogamp.newt.javafx.NewtCanvasJFX$5.changed(NewtCanvasJFX.java:153)
        at javafx.base/com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:181)
        at javafx.base/com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80)
        at javafx.base/javafx.beans.property.ReadOnlyObjectPropertyBase.fireValueChangedEvent(ReadOnlyObjectPropertyBase.java:74)
        at javafx.base/javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:102)
        at javafx.graphics/javafx.scene.Node$ReadOnlyObjectWrapperManualFire.fireSuperValueChangedEvent(Node.java:1050)
        at javafx.graphics/javafx.scene.Node.invalidatedScenes(Node.java:1121)
        at javafx.graphics/javafx.scene.Node.setScenes(Node.java:1159)
        at javafx.graphics/javafx.scene.Parent.scenesChanged(Parent.java:772)
        at javafx.graphics/javafx.scene.Node.invalidatedScenes(Node.java:1072)
        at javafx.graphics/javafx.scene.Node.setScenes(Node.java:1159)
        at javafx.graphics/javafx.scene.Scene$8.invalidated(Scene.java:1225)
        at javafx.base/javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
        at javafx.base/javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:147)
        at javafx.graphics/javafx.scene.Scene.setRoot(Scene.java:1178)
        at org.jogamp.joglojfx.App.start(App.java:99)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
        at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
        at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
        at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
        at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.IllegalAccessException: class com.jogamp.nativewindow.javafx.JFXAccessor cannot access class com.sun.javafx.tk.Toolkit (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.tk to unnamed module @250db1c8
        at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:376)
        at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:647)
        at java.base/java.lang.reflect.Method.invoke(Method.java:556)
        at com.jogamp.nativewindow.javafx.JFXAccessor.getJFXThread(JFXAccessor.java:190)
        ... 32 more

(java:16378): Gdk-WARNING **: 23:32:19.706: XSetErrorHandler() called with a GDK error trap pushed. Don't do that.
^CX11Util.Display: Shutdown (JVM shutdown: true, open (no close attempt): 1/1, reusable (open, marked uncloseable): 0, pending (open in creation order): 1)
X11Util: Open X11 Display Connections: 1
X11Util: Open[0]: NamedX11Display[:0, 0x7f1fd5d43c60, refCount 1, unCloseable false]

Sven, does it work with an older version of Java? I use Java 14 and OpenJFX 14.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Jogl and JavaFX

Sweck
@gouessej

I also get these errors on Java 12 and OpenJFX 14

if you remove this:

glCanvas.setWidth(800);
glCanvas.setHeight(600);

The code runs but doesnt call init or display from the gleventlistener.
Reply | Threaded
Open this post in threaded view
|

Re: Jogl and JavaFX

gouessej
Administrator
Yes I know that but we need to make the NewtCanvasJFX visible with a non-zero size. I have to use --add-exports to make it work.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Jogl and JavaFX

gouessej
Administrator
In reply to this post by Sweck
It allows to go a bit further:
java --module-path $PATH_TO_FX --add-modules javafx.controls --add-exports javafx.graphics/com.sun.javafx.tk=ALL-UNNAMED -cp target/classes:jogamp-fat.jar org.jogamp.joglojfx.App

but I get the following exception:
Exception in thread "JavaFX Application Thread" com.jogamp.nativewindow.NativeWindowException: Error getting JFX-Thread
        at com.jogamp.nativewindow.javafx.JFXAccessor.getJFXThread(JFXAccessor.java:192)
        at com.jogamp.nativewindow.javafx.JFXAccessor.isJFXThreadOrHasJFXThreadStopped(JFXAccessor.java:217)
        at com.jogamp.nativewindow.javafx.JFXAccessor.runOnJFXThread(JFXAccessor.java:160)
        at com.jogamp.nativewindow.javafx.JFXAccessor.getWindowHandle(JFXAccessor.java:272)
        at com.jogamp.newt.javafx.NewtCanvasJFX.validateNative(NewtCanvasJFX.java:338)
        at com.jogamp.newt.javafx.NewtCanvasJFX.repaintAction(NewtCanvasJFX.java:174)
        at com.jogamp.newt.javafx.NewtCanvasJFX.access$200(NewtCanvasJFX.java:83)
        at com.jogamp.newt.javafx.NewtCanvasJFX$5.changed(NewtCanvasJFX.java:163)
        at com.jogamp.newt.javafx.NewtCanvasJFX$5.changed(NewtCanvasJFX.java:153)
        at javafx.base/com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:181)
        at javafx.base/com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80)
        at javafx.base/javafx.beans.property.ReadOnlyObjectPropertyBase.fireValueChangedEvent(ReadOnlyObjectPropertyBase.java:74)
        at javafx.base/javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:102)
        at javafx.graphics/javafx.scene.Node$ReadOnlyObjectWrapperManualFire.fireSuperValueChangedEvent(Node.java:1050)
        at javafx.graphics/javafx.scene.Node.invalidatedScenes(Node.java:1121)
        at javafx.graphics/javafx.scene.Node.setScenes(Node.java:1159)
        at javafx.graphics/javafx.scene.Parent$2.onChanged(Parent.java:372)
        at javafx.base/com.sun.javafx.collections.TrackableObservableList.lambda$new$0(TrackableObservableList.java:45)
        at javafx.base/com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
        at javafx.base/com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
        at javafx.base/javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
        at javafx.base/javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
        at javafx.base/javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
        at javafx.base/javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
        at javafx.base/javafx.collections.ModifiableObservableListBase.add(ModifiableObservableListBase.java:155)
        at java.base/java.util.AbstractList.add(AbstractList.java:111)
        at javafx.base/com.sun.javafx.collections.VetoableListDecorator.add(VetoableListDecorator.java:209)
        at org.jogamp.joglojfx.App.start(App.java:92)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
        at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
        at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
        at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
        at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.IllegalAccessException: class com.jogamp.nativewindow.javafx.JFXAccessor cannot access a member of class com.sun.javafx.tk.Toolkit (in module javafx.graphics) with modifiers "protected static"
        at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:376)
        at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:647)
        at java.base/java.lang.reflect.Method.invoke(Method.java:556)
        at com.jogamp.nativewindow.javafx.JFXAccessor.getJFXThread(JFXAccessor.java:190)
        ... 36 more

We have to modify JOGL itself to make it work, maybe calling setAccessible(true) would be enough to get rid of that.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Jogl and JavaFX

gouessej
Administrator
setAccessible(true) is already called here:
https://jogamp.org/cgit/jogl.git/tree/src/nativewindow/classes/com/jogamp/nativewindow/javafx/JFXAccessor.java#n85

I'll try to use --add-opens.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Jogl and JavaFX

gouessej
Administrator
Ok --add-opens allows deep reflection :) It helps. I have to go further.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Jogl and JavaFX

gouessej
Administrator
In reply to this post by Sweck
Yeah! I've just made it work, I see my rotating triangle in blue :) Just give me a few hours to write a tutorial, it will be better than throwing partial information here.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Jogl and JavaFX

gouessej
Administrator
In reply to this post by Sweck
https://gouessej.wordpress.com/2020/04/05/javafx-et-jogl-fonctionnent-ensemble-javafx-and-jogl-work-together/

Good luck. I'll improve it, don't worry. It's better than nothing.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Jogl and JavaFX

Sven Gothel
Administrator
In reply to this post by gouessej
On 4/5/20 1:34 PM, gouessej [via jogamp] wrote:
> Yeah! I've just made it work, I see my rotating triangle in blue :) Just give
> me a few hours to write a tutorial, it will be better than throwing partial
> information here.

Great job.

Indeed our unit test merely uses the old CLASSPATH instead of
modules, which still allows access to the internals w/o these
'thousands of switches' - so to speak.

We may want to add you test code in the JOGL demo sub package (w/o junit)
to have novices pleased? Your call Julien (me doing a git pull from a repo of
yours, jogamp or otherwise).

Hope you all enjoyed the beautiful spring.

Warm greetings,

~Sven
Reply | Threaded
Open this post in threaded view
|

Re: Jogl and JavaFX

gouessej
Administrator
Thank you but keep in mind that I mostly used your unit test as a source of inspiration. Thank you for your stuff :)

My project is non modular despite the use of OpenJFX as a module. I had to choose between the plague and the cholera because loading OpenJFX not as a module would have required to use the classpath and the library path by mentioning numerous JARs and native libraries whose names are subject to changes :s

I have to fix a few things and yes, we can add it into jogl-demos.
Julien Gouesse | Personal blog | Website
123