org.eclipse.swt.opengl.GLCanvas missing addGLEventListener

Hello all,
I’m quite new to jogl, so maybe my problem is well-known. I successfully wrote a simple app with an AWT Frame containing a javax.media.opengl.GLCanvas


Frame testFrame = new Frame("TestFrame");
testFrame.setSize( 512, 384 );
javax.media.opengl.GLCanvas canvas = new javax.media.opengl.GLCanvas();
canvas.addGLEventListener(new Renderer());
testFrame.add( canvas );

I wanted to do the same with org.eclipse.swt.opengl.GLCanvas, but I could not find the addGLEventListener() method. Actually I tried to write that:


final Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
Composite parent = new Composite(shell, SWT.NONE);
parent.setLayout(new FillLayout());
		
GLData data = new GLData ();
data.doubleBuffer = true;
final org.eclipse.swt.opengl.GLCanvas canvas = new org.eclipse.swt.opengl.GLCanvas(parent, SWT.NONE, data);
//canvas.addGLEventListener(new Renderer()); // UNAVAILABLE!!

I could find the Snippet209 example that actually doesn’t use the GLEventListener interface, but I really would like to use it, in order to use the TraceGL, DebugGL and Animator tools.

Any idea? :-\

When using SWT, you have to do things a bit differently from the way they’re done in AWT. As you’ve already discovered, there is no ‘addGLEventListener()’ for SWT, nor is there a kind of GLEventListener like there is in JOGL.

If you want to use DebugGL/TraceGL, you’re going to have to construct them yourself. The Animator can still be used in conjunction with SWT.
eg:


// Method called by Animator in some sort of SWT window class you've writte
public void renderWindow(GL gl) {

    display.syncExec(new Runnable() {
        DebugGL debugGL = new DebugGL(gl);
        for (RenderTarget renderTarget: all of your renderable items, however you've organized them) {
            renderTarget.render(debugGL);
        }
    });

}

I think it’s something like that anyway (I do use SWT in my code, but I don’t use DebugGL/TraceGL/Animator, so aren’t too familiar with them).

Thanks for your explanation!
In a discussion (http://www.java-gaming.org/forums/index.php?topic=5904.msg57193#msg57193), a guy shows a piece of code using org.eclipse.swt.awt.SWT_AWT, in order to insert an AWT Frame into a SWT Composite.
This let him use JOGL in the “classical” way.
Do you have any opinion on this practice? Would you suggest to do that or to use the org.eclipse.swt.opengl.GLCanvas?

It’s really all up to you. If you are fond of the ‘classical’ JOGL way, then the SWT<->AWT bridge sounds like a pretty cool idea. I can see an advantage of this approach in that it’s more straight-forward to provide the option of selecting different GUI frameworks, while maintaining the same JOGL code between them.

Personally, I’m more fond of pure SWT than java.awt or javax.swing, mainly for the reason that I feel SWT gets things ‘right’ more often than AWT/Swing when it comes to reproducing the platform look-and-feel (eg: SWT has supported cleartype text and menu shadows on WindowsXP for a long time. AWT only just got cleartype text in Java 6, but still fails to do menu shadows).
So you’ll see me doing things similar to that seen in SWT code snippet 209; using display.(a)syncExec() to run the rendering loop, and so on.

OK, thanks for your answer!
Martin

Well, the SWT port 0.7 of JOGL doesn’t seams to ‘get things right’! I left a post concerning problems encountered with Text rendering (http://www.java-gaming.org/forums/index.php?topic=17447.0). So maybe I’ll use the SWT_AWT stuff :-\

Do you know which version of JOGL is incorporated into the SWT port 0.7.0? I could not find this information on the website…

Martin

I couldn’t find version information in the downloaded file either, or in some of the older SWT OpenGL posts, but the SWT port is usually a couple of release-candidates (maybe even a minor version) behind the current version of JOGL.