On Apple’s mac os x, is it possible to embed jogl in a swt composite?
If so, how?
If not, can I run jogl in a seperate window but together with swt from the same process?
thanks, jelle.
On Apple’s mac os x, is it possible to embed jogl in a swt composite?
If so, how?
If not, can I run jogl in a seperate window but together with swt from the same process?
thanks, jelle.
It’s not possible to run a SWT component from JOGL right now. Other alternative binds can
Cue Cas…
[quote]Cue Cas…
[/quote]
HAH!
What do you mean with other alternative binds can? if you know of any other bindings that can do the above on mac os x, please let me know.
thanks again,
jelle
lwjgl (http://lwjgl.org) is the other option refered to. However, lwjgl’s OS X support is a bit outdated. It will be brought up to date soon though.
I was digging through old posts and noticed this one. I just happened to try out JOGL with SWT yesterday, and to my surprise it works great - or so it seemed at least. Basically, I just used the following code to create the necessary SWT components:
Display display = new Display();
Shell shell = new Shell(display, SWT.EMBEDDED);
shell.setSize(640, 480);
Frame frame = SWT_AWT.new_Frame(shell);
GLCapabilities glCaps = new GLCapabilities();
glCaps.setHardwareAccelerated(true);
GLCanvas glCanvas = GLDrawableFactory.getFactory().createGLCanvas(glCaps);
glCanvas.addGLEventListener(this);
frame.add(glCanvas);
frame.setVisible(true);
shell.open();
Do you guys have any further ideas or experiences using JOGL with SWT?
Edit: This is actually really cool! I have no previous experience with SWT and I managed to create a working tabbed window component with JOGL canvases inside the tab items.
Edit2: The JOGL-SWT integration seems really robust. So far, I’ve experimented with different SWT components and event listeners attached to the GLCanvas - it all seems to work. Even the splitting components, such as SashForm (comparable to JSplitterPane in Swing…).
Yes you can very much run JOGL from SWT, though the mechanics of it is a little ‘interesting’.
Could you post a snippet showing how the SashForm integration works?
[quote]Could you post a snippet showing how the SashForm integration works?
[/quote]
Sure, here goes. This has been written in quite a hurry and tested with WinXP/J2SE1.5. To run the example, you need both JFace and SWT (plus the dll for the SWT). You can get them from the latest (stable!) Eclipse release (see under plugin directory…). I can write some kind of tutorial containing the necessary stuff, later on about this, if anyone is interested.
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import net.java.games.jogl.*;
import java.awt.Frame;
public class SWTExample
extends ApplicationWindow
{
private Animator animator;
public SWTExample()
{
super(null);
}
public SWTExample(Shell shell)
{
super(shell);
}
protected void configureShell(Shell shell)
{
super.configureShell(shell);
// Works with SWT 3.1.0 onwards...
//shell.setMinimumSize(400, 300);
shell.setSize(640, 480);
shell.setLocation(100, 100);
shell.setText("SWT Example");
}
protected Control createContents(Composite parent)
{
Shell shell = parent.getShell();
SashForm sashForm = new SashForm(shell, SWT.HORIZONTAL);
Composite compositeLeft = new Composite(sashForm, SWT.EMBEDDED);
Composite compositeRight = new Composite(sashForm, SWT.EMBEDDED);
setupGLCanvas(compositeRight);
sashForm.setWeights(new int[]{25, 75});
return parent;
}
private void setupGLCanvas(Composite composite)
{
Frame frame = SWT_AWT.new_Frame(composite);
GLCapabilities glCaps = new GLCapabilities();
glCaps.setHardwareAccelerated(true);
glCaps.setDoubleBuffered(true);
GLCanvas glCanvas = GLDrawableFactory.getFactory().createGLCanvas(glCaps);
glCanvas.addGLEventListener(new GLEventAdapter());
frame.add(glCanvas);
frame.setVisible(true);
animator = new Animator(glCanvas);
animator.start();
}
public void stop()
{
animator.stop();
}
public static void main(String[] args)
{
SWTExample swtExample = new SWTExample();
swtExample.setBlockOnOpen(true);
swtExample.open();
Display.getCurrent().dispose();
// This is required for the AWT frame to exit gracefully
// ...Animators should be stopped before this
swtExample.stop();
System.exit(0);
}
}
class GLEventAdapter
implements GLEventListener
{
public void init(GLDrawable glDrawable)
{
}
public void display(GLDrawable glDrawable)
{
// Clear the canvas
GL gl = glDrawable.getGL();
gl.glClearColor(System.currentTimeMillis() % 1000 * 0.001f, 0, 0, 0);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
}
public void reshape(GLDrawable glDrawable, int i, int i1, int i2, int i3)
{
}
public void displayChanged(GLDrawable glDrawable, boolean b, boolean b1)
{
}
}