import static com.jogamp.opengl.GL2ES3.GL_COLOR; import static com.jogamp.opengl.GL2ES3.GL_DEPTH; import java.nio.FloatBuffer; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import com.jogamp.opengl.GL4; import com.jogamp.opengl.GLAutoDrawable; import com.jogamp.opengl.GLEventListener; import com.jogamp.opengl.swt.GLCanvas; import com.jogamp.opengl.util.GLBuffers; public class OpenGLTest extends GLCanvas implements GLEventListener { public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display, SWT.RESIZE | SWT.MAX | SWT.CLOSE); shell.setSize(700, 600); shell.setText("Simple SWT viewer"); shell.setLayout(new FillLayout(SWT.VERTICAL)); new OpenGLTest(shell, SWT.NONE); shell.open(); while ( !shell.isDisposed() ) { if ( !display.readAndDispatch() ) display.sleep(); } display.dispose(); } private OpenGLTest(final Composite parent, final int style) { super(parent, SWT.NO_MERGE_PAINTS, null, null); addGLEventListener(this); } @Override public void init(GLAutoDrawable drawable) {} @Override public void dispose(GLAutoDrawable drawable) {} @Override public void display(GLAutoDrawable drawable) { GL4 gl = drawable.getGL().getGL4(); FloatBuffer clearColor = GLBuffers.newDirectFloatBuffer(4); FloatBuffer clearDepth = GLBuffers.newDirectFloatBuffer(1); gl.glClearBufferfv(GL_COLOR, 0, clearColor.put(0, 1f).put(1, .5f).put(2, 0f).put(3, 1f)); gl.glClearBufferfv(GL_DEPTH, 0, clearDepth.put(0, 1f)); // redraw(); } @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { } }