JOGL 2.4 - Canvas White Screen

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

JOGL 2.4 - Canvas White Screen

jim1987s
This post was updated on .
Good afternoon,

I've recently undertaken a project where I am required to convert a very old (8yrs+) JOGL (what appears to be a pre-1.1.1 version) application to JOGL 2.4 so that it will run without issue on Java 8.
I should specify I am currently running MacOS Mojave 10.14.3 and Java 8u201.
Initially, I had no problem working on this. I was able to include the new JOGL 2.4 library (jogamp-fat.jar from http://jogamp.org/deployment/archive/master/gluegen_910-joal_636-jogl_1474-jocl_1112/fat/) to my project, and just had to change `GL` to `GL2` (and correct some method names from calling their ARB variant to their plain variant).
However, the part of the application where I actually initialize OpenGL seems to be a bit tricky.

For reference, here is the old (antiquated) implementation:
https://gist.github.com/jim1987s/3fd724d737a97f04654b2c94ed03ff63
The method of note is `startToolkit`.

The main issue I found was that:
GLDrawableFactory glDrawableFac = GLDrawableFactory.getFactory();
glDrawable = glDrawableFac.getGLDrawable(canvas, glCapabilities, null);
...does not exist in JOGL 2.4.

As such, here is my attempted implementation for startToolkit:
https://gist.github.com/jim1987s/687d4ae03385b70d358b616171ab1b89

For all intents and purposes, it *appears* to work. I am able to start the application, but after it loads, the Canvas is white. I can interact with it still (clicking on components and typing yields print statements in the Console), yet of course, this is not what I desire.

I have also run this application using Debug and Verbose mode to get as much information as possible, which is shown at: https://gist.github.com/jim1987s/55c19acd0fd84f74044ea87813ef3a0a

I feel I am missing something small, and have spent a few days trying different approaches to no avail.

Any help would be greatly appreciated.


All the best,
Jim
Reply | Threaded
Open this post in threaded view
|

Re: JOGL 2.4 - Canvas White Screen

gouessej
Administrator
Hello

At first, there is no JOGL 2.4 yet despite what is printed in the debug output. The latest version available right now is JOGL 2.3.2. You posted a link to a build of JOGL 2.3.2 with a few changes.

Please provide a SSCCE to reproduce your problem.

By the way, your source code violates some important principles. You mustn't store a GL instance into a field because it can get invalidated and you could be tempted to use it either when it's no longer valid or when you're not on the thread on which it's current. Rather use the static method GLContext.getCurrentGL(), use it only when you're sure that the OpenGL context is current, preferably in a GLEventListener.

I advise you to look at my source code as JogAmp's Ardor3D Continuation has to do something similar and JogAmp's Java3D 1.7 too. I remember that something changed in the threading between JOGL 1 and JOGL 2, I had to take that into account when porting Ardor3D from JOGL 1 to JOGL 2.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: JOGL 2.4 - Canvas White Screen

jim1987s
Hi Julien,

Thank you for the reply, and thank you for pointing out a flaw in my design.
Unfortunately, I haven't had much time recently to create an SSCCE. However, I've followed your suggestions and want to make sure I am on the right track. The line(s) that I believe may be the culprit are:
GLCapabilities glCapabilities = new GLCapabilities();
GLDrawableFactory glDrawableFac = GLDrawableFactory.getFactory();
GLDrawable glDrawable = glDrawableFac.getGLDrawable(canvas, glCapabilities, null);
glDrawable.setRealized(true);
In the above and below implementations, `canvas` is just a java.awt.Canvas object.

Using JOGL 2.3.2 (as you rightfully clarified), I "converted" the lines above to interface with JOGL2:
GLProfile.initSingleton();
GLProfile glProfile = GLProfile.get(GLProfile.GL2);
GLCapabilities glCapabilities = new GLCapabilities(glProfile);
AWTGraphicsConfiguration config = AWTGraphicsConfiguration.create(canvas.getGraphicsConfiguration(), glCapabilities, glCapabilities);
JAWTWindow jawtWindow = NewtFactoryAWT.getNativeWindow(canvas, config);
GLDrawableFactory glDrawableFactory = GLDrawableFactory.getFactory(glProfile);
GLDrawable glDrawable = glDrawableFactory.createGLDrawable(jawtWindow);
glDrawable.setRealized(true);
Does this conversion seem correct, or am I overlooking something that was introduced from JOGL1 to JOGL2?


Additionally, I wanted to ask for some clarification on some debug output I am receiving.
Info: setGL (OpenGL 2.1 (Compat profile, arb, debug, compat[], FBO, hardware) - 2.1 NVIDIA-12.0.23 355.11.10.50.10.103): Thread-1, GL4bcImpl, jogamp.opengl.gl4.GL4bcImpl@4ec2bd58 -> DebugGL4bc, DebugGL4bc [this 0x22c5ab8e implementing com.jogamp.opengl.GL4bc,
	 downstream: jogamp.opengl.gl4.GL4bcImpl@4ec2bd58
Is it OK that
Thread-1
 is using GL4bcImpl, rather than some GL2-based implementation class?


Many thanks,
Jim
Reply | Threaded
Open this post in threaded view
|

Re: JOGL 2.4 - Canvas White Screen

gouessej
Administrator
GL4bcImpl implements GL2, nothing's wrong here.

Do you want to create an offscreen drawable? If it's not the case, why not using directly NewtCanvasAWT?

I've just checked in JogAmp's Ardor3D Continuation, I don't use JAWTWindow directly, Java3D is closer to what you're trying to achieve.
Julien Gouesse | Personal blog | Website