Example usage for org.eclipse.swt.opengl GL GL_FRONT_AND_BACK

List of usage examples for org.eclipse.swt.opengl GL GL_FRONT_AND_BACK

Introduction

In this page you can find the example usage for org.eclipse.swt.opengl GL GL_FRONT_AND_BACK.

Prototype

int GL_FRONT_AND_BACK

To view the source code for org.eclipse.swt.opengl GL GL_FRONT_AND_BACK.

Click Source Link

Usage

From source file:org.eclipse.swt.snippets.Snippet209.java

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Composite comp = new Composite(shell, SWT.NONE);
    comp.setLayout(new FillLayout());
    GLData data = new GLData();
    data.doubleBuffer = true;//from  w w w  .j ava  2 s  .  co m
    final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data);

    canvas.setCurrent();
    final GLContext context = GLDrawableFactory.getFactory(GLProfile.getGL2GL3()).createExternalGLContext();
    ;

    canvas.addListener(SWT.Resize, new Listener() {
        @Override
        public void handleEvent(Event event) {
            Rectangle bounds = canvas.getBounds();
            float fAspect = (float) bounds.width / (float) bounds.height;
            canvas.setCurrent();
            context.makeCurrent();
            GL2 gl = (GL2) context.getGL();
            gl.glViewport(0, 0, bounds.width, bounds.height);
            gl.glMatrixMode(GL2.GL_PROJECTION);
            gl.glLoadIdentity();
            GLU glu = new GLU();
            glu.gluPerspective(45.0f, fAspect, 0.5f, 400.0f);
            gl.glMatrixMode(GL2.GL_MODELVIEW);
            gl.glLoadIdentity();
            context.release();
        }
    });

    context.makeCurrent();
    GL2 gl = (GL2) context.getGL();
    gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    gl.glColor3f(1.0f, 0.0f, 0.0f);
    gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
    gl.glClearDepth(1.0);
    gl.glLineWidth(2);
    gl.glEnable(GL.GL_DEPTH_TEST);
    context.release();

    shell.setText("SWT/JOGL Example");
    shell.setSize(640, 480);
    shell.open();

    display.asyncExec(new Runnable() {
        int rot = 0;

        @Override
        public void run() {
            if (!canvas.isDisposed()) {
                canvas.setCurrent();
                context.makeCurrent();
                GL2 gl = (GL2) context.getGL();
                gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
                gl.glClearColor(.3f, .5f, .8f, 1.0f);
                gl.glLoadIdentity();
                gl.glTranslatef(0.0f, 0.0f, -10.0f);
                float frot = rot;
                gl.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f);
                gl.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f);
                rot++;
                gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2.GL_LINE);
                gl.glColor3f(0.9f, 0.9f, 0.9f);
                drawTorus(gl, 1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15);
                canvas.swapBuffers();
                context.release();
                display.asyncExec(this);
            }
        }
    });

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}