package org.slask.jogl; import javax.media.opengl.*; import javax.media.opengl.glu.GLU; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.*; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.newt.swt.NewtCanvasSWT; import com.jogamp.opengl.util.Animator; public class NewtSashTest { public NewtSashTest() { Display d = new Display(); Shell shell = new Shell(d); shell.setLayout(new FillLayout()); shell.setSize(400, 200); SashForm sash = new SashForm (shell, SWT.BORDER | SWT.HORIZONTAL); Text left = new Text(sash, SWT.CENTER); left.setText(" --- Left text ----"); BaseClass demo = new BaseClass(); GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2)); GLWindow glWindow1 = GLWindow.create(caps); glWindow1.addGLEventListener(demo); NewtCanvasSWT right = NewtCanvasSWT.create(sash, SWT.NO_BACKGROUND, glWindow1); shell.open(); Animator anim = new Animator(glWindow1); anim.start(); while (!shell.isDisposed()) { if (!d.readAndDispatch()) { d.sleep(); } } d.dispose(); System.exit(0); } class BaseClass implements GLEventListener { int x, y; int w, h; protected void setup(GL2 gl2) { gl2.glMatrixMode(GL2.GL_PROJECTION); gl2.glLoadIdentity(); // coordinate system origin at lower left with width and height same // as the window GLU glu = new GLU(); glu.gluOrtho2D(0.0f, w, 0.0f, h); gl2.glMatrixMode(GL2.GL_MODELVIEW); gl2.glLoadIdentity(); gl2.glViewport(0, 0, w, h); } protected void render(GL2 gl2) { gl2.glClear(GL.GL_COLOR_BUFFER_BIT); // draw a triangle filling the window gl2.glLoadIdentity(); gl2.glBegin(GL.GL_TRIANGLES); gl2.glColor3f(1, 0, 0); gl2.glVertex2f(0, 0); gl2.glColor3f(0, 1, 0); gl2.glVertex2f(w, 0); gl2.glColor3f(0, 0, 1); gl2.glVertex2f(w / 2, h); gl2.glEnd(); } @Override public void display(GLAutoDrawable arg0) { render((GL2) arg0.getGL()); } @Override public void dispose(GLAutoDrawable arg0) { } @Override public void init(GLAutoDrawable arg0) { setup((GL2) arg0.getGL()); } @Override public void reshape(GLAutoDrawable arg0, int x, int y, int w, int h) { this.x = x; this.y = y; this.w = w; this.h = h; setup((GL2) arg0.getGL()); } } public static void main(String args[]){ new NewtSashTest(); } }