gmseed
Posts: 35
Joined: Sat Aug 29, 2015 7:16 pm

JOGL, Swing and BlueJ

Sun Sep 20, 2015 9:17 am

I'm trying to setup a basic example of a JFrame with JOGL using BlueJ (v3.1.5) as the IDE on a Model 2 B RPi.

1) Get an example from Wiki:

https://en.wikipedia.org/wiki/Jogl

and follow the example link to:

https://gist.github.com/gouessej/3420e2b6f632efdddf98

2) Create a New Project in BlueJ called "JOGLQuad" and new class "JOGLQuad".

3) Add the jars via Tools|Preferences|Libraries and add:

.../jogamp-all-plafforms/jar/gluegen-rt.jar
.../jogamp-all-plafforms/jar/jogl-all.jar

Reset the JVM as required by BlueJ by selecting Tools|Reset JVM.

4) Which, if any, native jars to add? I've read the information at:

https://jogamp.org/jogl/doc/userguide/# ... aryloading

but still unclear as to what natives to add and how using BlueJ.

Presumably for this Swing app we stay clear of the "no-awt" versions.

BlueJ uses the following hard float version of Java:

/usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt

so do we add the "...armv6hf" jars? What does the v6 refer to and does this conflict with the version 8 Java?

5) Run the above example and get the following runtime exception:

Code: Select all

glGetError 0x500
glGetError 0x500
java.lang.ClassCastException: com.jogamp.nativewindow.DefaultGraphicsConfiguration cannot be cast to com.jogamp.nativewindow.awt.AWTGraphicsConfiguration
	at com.jogamp.opengl.awt.GLCanvas.chooseGraphicsConfiguration(GLCanvas.java:1557)
	at com.jogamp.opengl.awt.GLCanvas.addNotify(GLCanvas.java:615)
	at java.awt.Container.addNotify(Container.java:2773)
	at javax.swing.JComponent.addNotify(JComponent.java:4740)
	at java.awt.Container.addNotify(Container.java:2773)
	at javax.swing.JComponent.addNotify(JComponent.java:4740)
	at java.awt.Container.addNotify(Container.java:2773)
	at javax.swing.JComponent.addNotify(JComponent.java:4740)
	at javax.swing.JRootPane.addNotify(JRootPane.java:757)
	at java.awt.Container.addNotify(Container.java:2773)
	at java.awt.Window.addNotify(Window.java:770)
	at java.awt.Frame.addNotify(Frame.java:487)
	at java.awt.Window.pack(Window.java:807)
	at ExampleJOGL.<init>(ExampleJOGL.java:168)
	at ExampleJOGL.main(ExampleJOGL.java:364)
The above example is run just with gluegen-rt.jar and jogl-all.jar jars added to "User Libraries"; ie no natives added to the user lib directory.

6) In setting up the GLCapabiliies is the correct one?:

GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GLES2));
...
this.canvas = new GLCanvas(caps);

for example, to get the dyn4j ExampleJOGL example running at:

https://github.com/wnbittle/dyn4j/blob/ ... eJOGL.java

which, incidentally, gives the same runtime exception as the above JOGLQuad example.

6) I get the same runtime exception if I run unit test the JOGL TestSwingAWT01GLn:

Code: Select all

pi@raspberrypi ~/jogamp-all-platforms $ /usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt/jre/bin/java -cp jar/jogl-all.jar:jar/gluegen-rt.jar:/usr/share/java/junit4.jar:jar/jogl-test.jar:jar/gluegen-test-util.jar com/jogamp/opengl/test/junit/jogl/awt/TestSwingAWT01GLn

Code: Select all

JUnit version 4.10
++++ Test Singleton.ctor()
...
There was 1 failure:
1) test01GLDefault(com.jogamp.opengl.test.junit.jogl.awt.TestSwingAWT01GLn)
java.lang.reflect.InvocationTargetException
...
Caused by: java.lang.ClassCastException: com.jogamp.nativewindow.DefaultGraphicsConfiguration cannot be cast to com.jogamp.nativewindow.awt.AWTGraphicsConfiguration
...
7) Is there a "dummies" guide on either the RPi or JogAmp websites to getting a basic Swing app working?

Thanks
Graham

User avatar
xranby
Posts: 540
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: JOGL, Swing and BlueJ

Sun Sep 20, 2015 9:58 am

Three solutions to your issue below: A, B and C

Solution A
(hard, require modification of JOGL, a good solution in log term):
Mixing OpenGL ES 1 or OpenGL ES 2 in combination with xorg X11 windows is not easily done one the Raspberry Pi when using the Broadcom OpenGL ES driver.

The technical reason is that the Broadcom OpenGL ES driver must render to a "DispmanX" surface something that an xorg X11 window is not.
This limitation with the Broadcom OpenGL ES driver is well known and currently prevents mixing OpenGL ES with AWT/Swing because AWT/Swing uses xorg X11 windows.

We do have some advanced ideas how JOGL can be enhanced to support mixing Broadcoms OpenGL ES and AWT/Swing, the solution would be to render to an invisible DispmanX surface and then "blit", copy, the result from DispmanX to a AWT/Swing xorg X11 window. We do have an Enhancement bugreport in JogAmp JOGL that needs to be worked on for this idea to work.
https://jogamp.org/bugzilla/show_bug.cgi?id=626#c3


Solution B (medium, require modification of the pi system, the best solution for long term):
There is way to make JOGL OpenGL 2 work in combination with AWT/Swing on the Pi. This is done by replacing the Broadcom OpenGL ES 2 GPU driver with a new Mesa3D OpenGL 2 GPU driver.

You may use the new free software Mesa3D vc4 OpenGL 2 driver developed by Eric Anholt
this new OpenGL driver work in combination with AWT/Swing.
If you have a spare SD-card then I have written about a way to install a Raspbian system that is tweaked to use this new Mesa3D vc4 OpenGL 2 driver here:
viewtopic.php?f=81&t=115350
When you start the Pi using this system image then your Bluej + Swing + JOGL application will work without any further modifications.


Solution C (easy, workaround the issue, require modification of your JOGL application):
The example application JOGLQuad done by GouesseJ uses OpenGL 2, GL2, and depends on AWT/Swing using a GLCanvas and a Frame.
https://gist.github.com/gouessej/3420e2b6f632efdddf98
The Raspberry Pi only support OpenGL ES 1 & OpenGL ES 2 and can not mix OpenGL ES with AWT/Swing.
The solution is to rewrite the example application using OpenGL ES 1, GLES1 / GL2ES1, or OpenGL ES 2 using GLES2 / GL2ES2 profile
and then render using a GLWindow that would make the code supported on the Pi using the default driver.
I can port the JOGLQuad application to use a supported configuration, just wait a moment and i can post an example code replacement.
When you use a com.jogamp.newt.opengl.GLWindow then JOGL will render to a DispmanX surface and your application will work even from command line console and work in combination with the Broadcom OpenGL ES driver.
Last edited by xranby on Mon Sep 21, 2015 7:54 am, edited 3 times in total.
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

User avatar
xranby
Posts: 540
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: JOGL, Swing and BlueJ

Sun Sep 20, 2015 1:09 pm

xranby wrote: Solution C (easy, workaround the issue, require modification of your JOGL application):
The example application JOGLQuad done by GouesseJ uses OpenGL 2, GL2, and depends on AWT/Swing using a GLCanvas and a Frame.
https://gist.github.com/gouessej/3420e2b6f632efdddf98
The Raspberry Pi Broadcom OpenGL ES driver only support OpenGL ES 1 & OpenGL ES 2 and can not mix OpenGL ES with AWT/Swing.
The solution is to rewrite the example application using OpenGL ES 1, GLES1 / GL2ES1, or OpenGL ES 2 using GLES2 / GL2ES2 profile
and then render using a GLWindow that would make the code supported on the Pi using the default driver.
...
When you use a com.jogamp.newt.opengl.GLWindow then JOGL will render to a DispmanX surface and your application will work even from command line console and work in combination with the Broadcom OpenGL ES driver.
Here is a port of JOGLQuad called JOGLQuadES1
Note that this example only require Bluej + JOGL to run. I have removed use of all AWT/Swing classes.
https://gist.github.com/xranby/ccbcfcaef341f5bd1ba8

If you read the soucecode to JOGLQuadES1 using the link above you will notice that I use a class called ImmModeSink in order to emulate fixed functionality of OpenGL 2 on OpenGL ES 1 hardware to ease the port from using GL2 to GL2ES1 profile.
http://jogamp.org/deployment/jogamp-cur ... eSink.html

You can use this example on the Pi.
If you use it from inside Bluej then create a class JOGLQuadES1 and paste the content from the url. Press compile and then right click on the class and select void main({}) to run it.

If you want to test the demo from a text console
then run:

Code: Select all

wget http://jogamp.org/deployment/archive/master/gluegen_891-joal_617-jogl_1442-jocl_1087-signed/fat/jogamp-fat.jar
wget https://gist.githubusercontent.com/xranby/ccbcfcaef341f5bd1ba8/raw/6617c1f19c4feac26a28b24756e0983c65b212b3/JOGLQuadES1.java
javac -cp jogamp-fat.jar JOGLQuadES1.java
java -cp jogamp-fat.jar:. JOGLQuadES1
Last edited by xranby on Wed Sep 23, 2015 10:58 am, edited 1 time in total.
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

gmseed
Posts: 35
Joined: Sat Aug 29, 2015 7:16 pm

Re: JOGL, Swing and BlueJ

Sun Sep 20, 2015 4:10 pm

Thanks for taking the time to rejig the example.

It runs, but I get red errors (glGetError 0x500) in the terminal window. Also it generates 2 cursors and does pretty weird things. A bit unusable really.

Also, what I was really interested in is adding an OpenGL canvas to a JFrame window or JPanel. Is this not currently possible; ie source of errors previously posted? As in the wiki and dyn4j examples.

I took a screen dump, but it doesn't show the 2 cursors and other problems so not much use really.

Graham

Image

User avatar
xranby
Posts: 540
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: JOGL, Swing and BlueJ

Sun Sep 20, 2015 5:14 pm

gmseed wrote:Thanks for taking the time to rejig the example.

It runs, but I get red errors (glGetError 0x500) in the terminal window. Also it generates 2 cursors and does pretty weird things. A bit unusable really.
The Broadcom OpenGL ES driver is designed to be used from text-mode (before you run startx).
Thus if you run the JOGLQuadES1 class from text-mode then you will only see one white "dispmanx" mousecursor.

With JogAmp JOGL version 2.3.1 and below you will see dual mousepointers (one white "dispmanx" mousecursor and one black "xorg" mousecursor) if you try to use opengl after you have started xorg. Also the red errors (glGetError 0x500) are seen using the JOGL 2.3.1 version and lower.

I am working on enhancing the xorg experience for the 2.3.2 release:
https://jogamp.org/bugzilla/show_bug.cgi?id=1178 - Prevent dual mousepointers and improve raspberry pi xorg experience when using NEWT BCM VC IV on Raspberry Pi
Much of the enhancement code has already been merged thus if you use the jogamp-fat.jar mentioned from the pre-release then you will have a better experience.
gmseed wrote: Also, what I was really interested in is adding an OpenGL canvas to a JFrame window or JPanel. Is this not currently possible;
ie source of errors previously posted? As in the wiki and dyn4j examples.
Using OpenGL ES in combination with a JFrame or JPanel is not possible using the Broadcom provided OpenGL driver unless someone implement Solution A.

You can today use Solution B if you want, by using the Mesa3D provided OpenGL driver.
Mesa3D OpenGL driver using CPU rendering is pre-installed on all Rasbian systems all you have to do to use this driver is to "disable" the Broadcom driver.
You can "disable" the Broadcom driver by making the /opt/vc folder un-accessible like this:
sudo mv /opt/vc /opt/vc-off
Then try re-run the JOGLQuad class!
If that work for you and you want to try Mesa3D OpenGL driver with GPU acceleration then do test Eric Anholts new vc4 driver as mentioned above.
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

gmseed
Posts: 35
Joined: Sat Aug 29, 2015 7:16 pm

Re: JOGL, Swing and BlueJ

Sun Sep 20, 2015 5:32 pm

Thanks for all your help but I think I'll give up on jogl2 on the RPi! I'm not an opengl, jogl, linux expert!!

I'd like to use it out of the box and not start installing any different drivers.

Also, being able to place or embed an opengl window on a canvas is a basic requirement for using Java Swing, and really my main interest, and if this isn't currently possible then I'll have to consider something else.

A few years ago I spent/wasted a lot of time with Ardor3D and had a hell of a lot problems with that too, for what should have been basic stuff. It must be the nature of opengl and the variety of differwnt graphics drivers, operating systems and hardware...

Anyway, thanks again for all your help.
Last edited by gmseed on Sun Sep 20, 2015 10:08 pm, edited 1 time in total.

User avatar
xranby
Posts: 540
Joined: Sat Mar 03, 2012 10:02 pm
Contact: Website

Re: JOGL, Swing and BlueJ

Sun Sep 20, 2015 5:43 pm

gmseed wrote:Thanks for all your help but I think I'll give up on jogl2 on the RPi! I'm not an opengl, jogl, linux expert!!

I'd like to use it out of the box and not start installing any different drivers.

Also, being able to place or embed an opengl window on a canvas is a basic requirement for using Java Swing, and really my main interest, and if this isn't currently possible then I'll have to consider something else.
I will keep you informed when Solution A is implemented, placing a Swing canvas that OpenGL can render to into your application will then work out of the box, however you are still limited to using OpenGL ES 1 or OpenGL ES 2 since the Broadcom opengl es driver only implement that.

I will also tell when Eric Anholt's Mesa3D driver, Solution B, is installed by default, placing a Swing canvas that OpenGL can render to into the application will then also work out of the box.
There already exist system images that you can write to a SD card to test the new driver: http://sukzessiv.net/~gohai/vc4-buildbot/build/
After the pi have started from this system image then you are using Solution B.
gmseed wrote: A few years ago I spent/wasted a lot of time with Ardor3D and had a hell of a lot problems with that too, for what should have been basic stuff. It must be the nature of opengl and the variety of differwnt graphics drivers, operating systems and hardware...

Anyway, thanks again for all your help.
Yes it is unfortunate that there is still high secrecy around how GPUs operate in the computer industry. Todays need to update large screens at high framerates makes using a GPU a must have requirement.

Your desire and need to mix Swing and OpenGL GPU rendering can only be done if Swing and OpenGL operated using the same window types.
The OpenGL API gives the user a unified access to the GPU hardware, however the OpenGL standard do not mention how a window is to be initialised.
Every major operating system such as Andoid, Windows, Mac & Linux+Xorg uses different window initialisation and types.

The window type required for GPU acceleration define what is a new operating system. The Raspberry Pi using the default Broadcom OpenGL ES driver is by this definition a new operating system that require all applications to use dispmanx window types.

Thus as you say a simple thing such as opening a window that can use GPU OpenGL hardware acceleration is done differently for every operating system and thats why it is a hard problem.

Ardor3D will also work out of the box if you use Solution A or Solution B.
Solution B allows you to run any OpenGL 2 application on the Pi, I have already sucessfully run the full version of Minecraft and Minetest using this new driver.
Eric Anholt is hired by Broadcom to create this new driver inside the Mesa3D project that is compatible with all OpenGL 2 software. Kudos to Eric and Broadcom for making it a reality!


I write verbose answers because there is always more than one person reading the posts to the forum.
I hope my answers has given you at least a better idea how OpenGL on the raspberry pi work and how it can be enhanced.
Xerxes Rånby @xranby I once had two, then I gave one away. Now both are in use every day!
twitter.com/xranby

Helmut Pithan
Posts: 3
Joined: Sat Nov 28, 2015 9:05 am

Re: JOGL, Swing and BlueJ

Sat Nov 28, 2015 10:12 am

I used the Mesa and DRM driver for Broadcom VC4.
(Builds of raspbian using the driver can be found at http://sukzessiv.net/~gohai/vc4-buildbot/build/)

There I copied the contents of
/usr/local/lib/processing-3.0.1/core/library
to
/usr/share/bluej/userlib

Now I can use JOGL with Bluej and many of the java3d-examples (gear,virtual rob, ObjectLoader, MouseRotateApp, ExAmbientLight) run with Bluej.
You have to start these examples from their main method not as applet.
There are same problems with the used build of raspian.
When I try to move a window, the system crashes.
Sometimes the content of a java3d-window needs a mouse activity to appear.

Return to “Java”