Login  Register

Looking for example using SWT GLCanvas

Posted by drstine on Jul 19, 2012; 7:55pm
URL: https://forum.jogamp.org/Looking-for-example-using-SWT-GLCanvas-tp4025603.html

Greetings,

Thanks for the good work you all are doing on JOGL.  I'm about to port a large engineering graphics application to Eclipse RCP (Indigo).  Right now I'm exploring the best windowing toolkit to tie our OpenGL/JOGL code to our Eclipse RCP/SWT views.  I'm developing on Windows XP(32bit) with Java 1.7SE update 2 and  JOGL v2.0-rc9.

I've read the tutorials and JavaDocs for Eclipse RCP/SWT/JOGL and have managed to produce evaluation tests for #1 and #2 of the four options Julien posted here.

1) [WORKS] the obsolete org.eclipse.swt.opengl.GLCanvas (thanks to Wade's excellent wiki article)

                org.eclipse.swt.widgets.Composite parent;

                // canvas
                javax.media.opengl.GLProfile glprofile = GLProfile.getDefault();
                org.eclipse.swt.opengl.GLData gldata = new GLData();
                import org.eclipse.swt.opengl.glCanvas = new org.eclipse.swt.opengl.GLCanvas(parent,
                                                                                                              SWT.NO_BACKGROUND, gldata);
                // OpenGL context
                javax.media.opengl.GLContext glContext = GLDrawableFactory.getFactory(glprofile).
                                                                                                createExternalGLContext();

2) [WORKS]  javax.media.opengl.awt.GLCanvas via org.eclipse.swt.awt.SWT_AWT (from the same article)

                org.eclipse.swt.widgets.Composite parent;

                // canvas
                javax.media.opengl.awt.GLCanvas glCanvas = new GLCanvas();

                // bridge
                final org.eclipse.swt.Composite composite = new Composite(parent, SWT.EMBEDDED|SWT.NO_BACKGROUND);
                java.awt.Frame frame = SWT_AWT.new_Frame(composite);
                frame.add(glCanvas);

3) [WORKS]  com.jogamp.newt.opengl.GLWindow via com.jogamp.newt.awt.NewtCanvasAWT via org.eclipse.swt.awt.SWT_AWT

                org.eclipse.swt.widgets.Composite parent;

                // window
                javax.media.opengl.GLProfile glprofile = GLProfile.getDefault();
                javax.media.opengl.GLCapabilities caps = new GLCapabilities(glprofile);
                com.jogamp.newt.opengl.glWindow = GLWindow.create(caps);

                // canvas
                com.jogamp.newt.awt.NewtCanvasAWT canvas = new NewtCanvasAWT(glWindow);

                // bridge
                final org.eclipse.swt.Composite composite = new Composite(parent, SWT.EMBEDDED|SWT.NO_BACKGROUND);
                java.awt.Frame frame = SWT_AWT.new_Frame(composite);
                frame.add(canvas);

Seems doable but seems a bit convoluted... is this really a practical option?  Does it provide any unique advantage over the others?

4) [EXCEPTION] com.jogamp.opengl.swt.GLCanvas

I modified #1 to use the new SWT GLCanvas but cannot get #4 to run.  I get a java.lang.ClassNotFoundException: org.eclipse.swt.widgets.Canvas thrown from the constructor of  com.jogamp.opengl.swt.GLCanvas.  (It compiles fine.)

Does anyone have a few lines of example code that demonstrate how to use the SWT GLCanvas?  Wade mentioned that he might try this last April.  Could you post a sample?

I see that there is an "in progress" feature request for a native SWT binding.  Do I need to wait for that or can I use rc9 with some amount of cleverness?

Regards,
Dan