GLCanvas wit overlay

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

GLCanvas wit overlay

psyko
Hello,

I'm using the swt GLCanvas (com.jogamp.opengl.swt.GLCanvas) in combination with an Overlay (com.jogamp.opengl.util.awt.Overlay) to display some textual information.
It works fine on Windows, but doesn't work on MacOS because Overlay works with an internal TextureRenderer  (com.jogamp.opengl.util.awt.TextureRenderer) which force the use of a GL2 (which is not available on Mac).
My application is designed to work with most recent GL4.

Is there any way to have a GL4 compatible overlay ?
I wanted to use the drawing capabilities of SWT graphics, but I'm struggling with the synchronisation of SWT and GL rendering. SWT actions should be done in the main UI thread and I'm not sure how to sync that with every frame of the GLCanvas.

Thank you,
Psyko
Reply | Threaded
Open this post in threaded view
|

Re: GLCanvas wit overlay

gouessej
Administrator
Hello

There is a pull request about adding GL3 and GL4 support into com.jogamp.opengl.util.awt.TextureRenderer but it's not integrated into JOGL yet. Either update this contribution to make it work with the latest JOGL version or use the shader based text renderer (see com.jogamp.graph).

I used SWT and Eclipse RCP for years, I advise you to avoid mixing SWT and AWT. The OpenGL rendering of the heayweight com.jogamp.opengl.swt.GLCanvas should be performed on the same thread than the SWT rendering. If you have a doubt, use GLCanvas.invoke().
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GLCanvas wit overlay

psyko
Thanks for the answer. I'll also would like to avoid mixing SWT and AWT. So contributing to the GL3/4 support in the TextureRenderer is not the solution I4m looking for.

If I understand correctly, the rendering of overlay should be drawn on the SWT GC, right ?
So basically, I should use the GLCanvas.invoke() methods at each frame, which will queue a GLRunnable that will perform the drawing on the SWT component itself ?
If I understand correctly, GLCanvas.invoke() will be a one shot call, so I have to queue it for every frame ?

If you want context, the main display method of my app is visible here


Thanks
Reply | Threaded
Open this post in threaded view
|

Re: GLCanvas wit overlay

psyko
I tried to used GlCanvas.invoke(...)

		glcanvas = ... //create canvas
		glcanvas.invoke(true, new GLRunnable() {			
			@Override
			public boolean run(GLAutoDrawable arg0) {
				System.out.println("test");
				return true;
			}
		});
		animator = new FPSAnimator(30);
		animator.add(glcanvas);			
		animator.start();

But the GLRunnable is never run... Any idea of what I'm doing wrong ?
Thanks
Reply | Threaded
Open this post in threaded view
|

Re: GLCanvas wit overlay

gouessej
Administrator
In reply to this post by psyko
Actually, you shouldn't use the AWT overlay. You can look at the text rendering of other engines based on JOGL to make your own one, for example Jogamp's Ardor3D Continuation that supports SWT and uses JOGL 2.3.2 but its GL4 support isn't heavily tested, it uses PMWMatrix under the hood in some cases including for OpenGL-ES support.

JMonkeyEngine is worth a look too.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GLCanvas wit overlay

psyko
Correct, I'm not trying to use AWT overlay. I want to get rid of the com.jogamp.opengl.util.awt.Overlay.
I would like to draw on the SWT component instead. Not sure if that's what you're talking about.
I'm on the IRC if you have time to discuss it.
Reply | Threaded
Open this post in threaded view
|

Re: GLCanvas wit overlay

psyko
From what I understand, you're suggesting to use the common practice of having a quad facing the camera and drawing stuffs on it, correct ?
That's what I would like to avoid if possible.
Reply | Threaded
Open this post in threaded view
|

Re: GLCanvas wit overlay

gouessej
Administrator
In reply to this post by psyko
You should avoid using com.jogamp.opengl.util.awt.Overlay with SWT.

You should really read the Java documentation of GLCanvas.invoke(). You should post your Runnable after starting your Animator and you should pass "true" to GLCanvas.invoke() if and only if you absolutely need to run the Runnable now and if it doesn't risk to block the rendering.

No, you could simply draw your text with JOGL if possible or with an alternative overlay relying on SWT.

Have you looked at this?
http://forum.jogamp.org/How-to-overlay-SWT-Widgets-over-GLCanvas-td4029507.html
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GLCanvas wit overlay

psyko
Checking documentation is usually the first thing I do. I looked at the Javadoc of GLCanvas.invoke() but it doesn't help. I tried posting the runnable after and before the animator, with true and false: no success.

I managed to use SWT with a PaintListener, but the paint event on the SWT GLCanvas is not called at each frame. So it gets replaced by the GL content.
I tried attaching a GLEventListener to forward the display event and call a canvas.redraw() in a Display.async/sync, but with this method, it flickers a lot.


Reply | Threaded
Open this post in threaded view
|

Re: GLCanvas wit overlay

psyko
Yeah I took a look at http://forum.jogamp.org/How-to-overlay-SWT-Widgets-over-GLCanvas-td4029507.html
I have to try and add a Swt standard Canvas on top of my GLCanvas, but I'm not sure it's possible in SWT. Mouse event will not be received anymore by the GLCanvas. But this is only a guess. I have to give it a real try.
Reply | Threaded
Open this post in threaded view
|

Re: GLCanvas wit overlay

gouessej
Administrator
In reply to this post by psyko
I don't know what is wrong but this is what we do and it works:
https://github.com/gouessej/Ardor3D/blob/master/ardor3d-jogl-swt/src/main/java/com/ardor3d/framework/jogl/swt/JoglSwtCanvas.java#L87

redraw() will trigger the paint listener.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GLCanvas wit overlay

psyko
Hello again,

I just realized that using an FPSAnimator() creates an FPSAWTAnimator thread, which is not the same as the SWT UI thread.
Could that be causing any issue with the SWT Rendering part ?

Do I have to use some kind of SWT compatible animator ?
What is the alternative to using animator ? Coding my own loop thread ? Calling the redraw of the OpenGL from the SWT UI thread ?

Thank you,
Reply | Threaded
Open this post in threaded view
|

Re: GLCanvas wit overlay

gouessej
Administrator
Use a plain Animator and perhaps enable v-sync.
Julien Gouesse | Personal blog | Website