Posted by
adam_law on
Jun 27, 2015; 12:15am
URL: https://forum.jogamp.org/GLJPanel-for-LibGDX-JOGL-backend-tp4034741p4034765.html
yeah, I was able to nab a copy from the libgdx nightlies.
I've given it a shot, implementing LibGDX' Application and using pretty much the standard initialization that was in JoglApplication. I then had a GLJPanel member add an instance of NewtCanvasAWT(graphics.getCanvas()) to itself and I then added this GLJPanel to a SwingNode. Unfortunately, I get an error:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0
at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1016)
at java.awt.GraphicsConfiguration.createCompatibleImage(GraphicsConfiguration.java:186)
at sun.awt.image.SunVolatileImage.getBackupImage(SunVolatileImage.java:236)
at sun.awt.image.VolatileSurfaceManager.getBackupSurface(VolatileSurfaceManager.java:263)
at sun.awt.image.VolatileSurfaceManager.initialize(VolatileSurfaceManager.java:126)
at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:88)
at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:117)
at java.awt.GraphicsConfiguration.createCompatibleVolatileImage(GraphicsConfiguration.java:307)
at java.awt.GraphicsConfiguration.createCompatibleVolatileImage(GraphicsConfiguration.java:241)
I checked the dimensions of both SwingNode and the GLJPanel, and these weren't the culprits. I couldn't trace back as I don't have the source of some parts of that stack trace.
Any thoughts of my implementation and the error?
Edit: Forgot to add, letting the application continue, I get this next, where JoglPanel is the name of the custom class I wrote:
Exception in thread "JavaFX Application Thread-AWTAnimator#00" com.jogamp.opengl.util.AnimatorBase$UncaughtAnimatorException: com.jogamp.opengl.GLException: Caught ClassCastException: com.badlogic.gdx.backends.jogamp.JoglPanel cannot be cast to com.badlogic.gdx.backends.jogamp.JoglApplication on thread JavaFX Application Thread-AWTAnimator#00
at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:84)
at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:451)
at com.jogamp.opengl.util.Animator$MainLoop.run(Animator.java:198)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.jogamp.opengl.GLException: Caught ClassCastException: com.badlogic.gdx.backends.jogamp.JoglPanel cannot be cast to com.badlogic.gdx.backends.jogamp.JoglApplication on thread JavaFX Application Thread-AWTAnimator#00
I'm using Java 8 64-bit.
Edit #2: On one of your old posts, it mentioned people using GLJPanel successfully with SwingNode, would you happen to know where there might the code snippet for that?
Edit #3: I was able to circumvent the IllegalArgumentException by setting the canvas size at start based on a clue found
here. I used a modified version of JoglAWTCanvas since it was quicker for troubleshooting. I will amend the JoglPanel I wrote to extend JoglApplication instead of implementing Application, to fix the
ClassCastException.
While there no longer any errors when I used the modified JoglAWTCanvas, nothing is displaying. I'll try modifying JoglPanel and try that.
Edit #4: I broke through About a minute after my last edit, I remembered that I can't simply extend JoglApplication. It creates a NewtWindow in the process, running alongside my JavaFX based app.
I guess I'm getting close ? I see in JoglGraphicsBase that the GLWindow is created automatically, which I prevent by overriding JoglApplication's initialize and not setting graphics.getCanvas().setVisible() to true. Right now it's a black are where the embedded GLJPanel is within the SwingNode. Did I do the right bthing by not setting the canvas to visible? If it needs to be visible, how do I access what needs to be drawn on the GLJPanel without spawning a window? I also notice a hiccup / slowdown at startup, and this is true when I launch my app w/o the JavaFX parts as a JoglApplication.
Lastly, is there a need to override GLEventListener if this ever gets working?
Thanks.
Edit #5: Out of curiosity, I tried hooking up the canvas' GLEventListener to the GLJPanel via gljpanel.addGLEventListener(graphics.getCanvas().getGLEventListener(0)). Spat out an error where it failed the check for current context:
Caused by: com.jogamp.opengl.GLException: AWT-EventQueue-0: This context is not current. Current context: WindowsWGLContext