Example usage for org.lwjgl.opengl GL11 glLoadIdentity

List of usage examples for org.lwjgl.opengl GL11 glLoadIdentity

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL11 glLoadIdentity.

Prototype

public static native void glLoadIdentity();

Source Link

Document

Sets the current matrix to the identity matrix.

Usage

From source file:edu.csun.ecs.cs.multitouchj.ui.utility.OpenGlUtility.java

License:Apache License

public static void orthoMode(Size size) {
    GL11.glDisable(GL11.GL_DEPTH_TEST);//from w w  w.  j av a2 s.  c  om
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();
    GL11.glOrtho(0, size.getWidth(), 0, size.getHeight(), -10, 10);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();
}

From source file:espresso3d.engine.window.gui.E3DGuiHandler.java

License:Open Source License

public void render() {
    if (!isAnyGuiDisplaying())
        return;//from w  w w  .j  a  v a2 s  . c o  m

    GL11.glPushMatrix();
    getViewport().switchToViewport();
    GL11.glLoadIdentity();

    for (int i = 0; i < guiWindows.size(); i++) {
        E3DGuiWindow window = (E3DGuiWindow) guiWindows.get(i);
        window.render();
    }
    GL11.glPopMatrix();
}

From source file:espresso3d.engine.window.viewport.E3DViewport.java

License:Open Source License

/**
 * This will automatically be called by the engine.  Users needn't worry about this.
 * Sets the perspective to the values stored in this viewport.  This keeps track of whether
 * the values have changed or not, so it will keep the GL calls to a minimum (only set the perspective
 * if something has actually changed)./*w  w  w.ja v a 2s  .c o m*/
 *
 */
private void setPerspective() {
    if (perspectiveChanged) {
        GL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix
        GL11.glLoadIdentity(); // Reset The Projection Matrix

        if (mode == VIEWPORT_MODE_PERSPECTIVE) {
            // Calculate The Aspect Ratio Of The Window
            GLU.gluPerspective((float) fovY, (float) ((float) width / (float) height), (float) nearClipPlane,
                    (float) farClipPlane);
        } else if (mode == VIEWPORT_MODE_ORTHOGRAPHIC)
            GL11.glOrtho(left * orthoZoom, right * orthoZoom, bottom * orthoZoom, top * orthoZoom,
                    nearClipPlane, farClipPlane); //todo: this needs to center around the camera.  Need to determin whether to use X/Y, Y/Z, or X/Z to center on

        recalcProjectionViewMatrix();

        perspectiveChanged = false;
    }

    GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Projection Matrix
    GL11.glLoadIdentity(); // Reset The Modelview Matrix

    GL11.glDepthMask(true); //Re-enable this.  IF particles turn this off, it has to be turned on to be able to clear the depth buffer
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer

    GLU.gluLookAt((float) cameraActor.getOrientation().getPosition().getX(),
            (float) cameraActor.getOrientation().getPosition().getY(),
            (float) cameraActor.getOrientation().getPosition().getZ(),
            ((float) (cameraActor.getOrientation().getPosition().getX()
                    + cameraActor.getOrientation().getForward().getX())),
            ((float) (cameraActor.getOrientation().getPosition().getY()
                    + cameraActor.getOrientation().getForward().getY())),
            ((float) (cameraActor.getOrientation().getPosition().getZ()
                    + cameraActor.getOrientation().getForward().getZ())),
            (float) cameraActor.getOrientation().getUp().getX(),
            (float) cameraActor.getOrientation().getUp().getY(),
            (float) cameraActor.getOrientation().getUp().getZ());

    //If something has changed camera wise, we need to recalculate the viewport matrix 
    // the next time something asks for a projection or unprojection
    if (!cameraActor.getOrientation().getPosition().equals(lastPosition)
            || !cameraActor.getOrientation().getForward().equals(lastForward)
            || !cameraActor.getOrientation().getUp().equals(lastUp)) {
        lastPosition.set(cameraActor.getOrientation().getPosition());
        lastForward.set(cameraActor.getOrientation().getForward());
        lastUp.set(cameraActor.getOrientation().getUp());
        needViewArrayRecalc = true;
    }
}

From source file:espresso3d.engine.window.viewport.E3DViewport.java

License:Open Source License

public void render() {
    //Render viewport external renderables
    renderExternalRenderables();//www .j av a2  s  .  com

    GL11.glPushMatrix();
    GL11.glLoadIdentity();
    recalcModelViewMatrix(); //loaded identity, force the recalc for unprojection: TODO: Consider making a stack of these as well??

    //Render 2D Images in the viewport
    updateImages();
    //         getRenderTree().render();

    //Render 2D Font text
    getViewportPrinter().render(); //Put font on top of any image

    //            getRenderTree().render();

    GL11.glPopMatrix();
    recalcModelViewMatrix(); //put it back to the way it should be for everything else rendered
}

From source file:eu.over9000.veya.gui.Gui.java

License:Open Source License

private static void setUpStates(final int width, final int height) {
     try {/*from  w ww.  java  2s.c o  m*/
         Display.setDisplayMode(new DisplayMode(width, height));

         Display.create();
         //Display.create(new PixelFormat().withSamples(4).withDepthBits(24), new ContextAttribs(3, 3));
         Display.setVSyncEnabled(true);
     } catch (final LWJGLException e) {
         e.printStackTrace();
         System.exit(0);
     }

     GL11.glEnable(GL11.GL_TEXTURE_2D);
     GL11.glShadeModel(GL11.GL_SMOOTH);
     GL11.glDisable(GL11.GL_DEPTH_TEST);
     GL11.glDisable(GL11.GL_LIGHTING);

     GL11.glClearColor(0.0f, 0.3f, 0.0f, 0.0f);
     GL11.glClearDepth(1);

     GL11.glEnable(GL11.GL_BLEND);
     GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

     GL11.glViewport(0, 0, width, height);
     GL11.glMatrixMode(GL11.GL_MODELVIEW);

     GL11.glMatrixMode(GL11.GL_PROJECTION);
     GL11.glLoadIdentity();
     GL11.glOrtho(0, width, height, 0, 1, -1);
     GL11.glMatrixMode(GL11.GL_MODELVIEW);
 }

From source file:fable.framework.ui.views.chiPlotView.java

License:Open Source License

/**
 * This is a callback that will allow us to create the viewer and initialize
 * it./*  w  w w .  j  a v a 2 s.  c  o  m*/
 */
/*
 * (non-Javadoc)
 * 
 * @see
 * org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets
 * .Composite)
 */
/*
 * (non-Javadoc)
 * 
 * @see
 * org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets
 * .Composite)
 */
public void createPartControl(Composite parent) {

    // logger = FableLogger.getLogger();
    console = new FableMessageConsole("Peaksearch console");
    ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console });
    console.displayOut("Welcome to chiplotview " + ToolBox.getPluginVersion(Activator.PLUGIN_ID));

    IOConsoleOutputStream stream = console.newOutputStream();

    // console_debug = new ConsoleLineTracker();

    System.setOut(new PrintStream(stream, true));
    System.setErr(new PrintStream(stream));

    thisView = this;
    parent.setLayout(new GridLayout());
    Composite controlPanelComposite = new Composite(parent, SWT.NULL);
    GridLayout controlGridLayout = new GridLayout();
    controlGridLayout.numColumns = 8;
    controlPanelComposite.setLayout(controlGridLayout);
    controlPanelComposite.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
    freezeButton = new Button(controlPanelComposite, SWT.CHECK);
    freezeButton.setText("Freeze");
    freezeButton.setToolTipText("freeze 3d relief, disable rotation");
    freezeButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            if (freezeButton.getSelection())
                freeze = true;
            else
                freeze = false;
        }
    });
    resetButton = new Button(controlPanelComposite, SWT.NULL);
    resetButton.setText("Reset");
    resetButton.setToolTipText("reset 3d projection to be flat and fill the canvas");
    resetButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            grip.init();
        }
    });
    autoscaleButton = new Button(controlPanelComposite, SWT.CHECK);
    autoscaleButton.setText("Autoscale");
    autoscaleButton.setToolTipText("autoscale 3d relief between minimum and mean");
    autoscaleButton.setSelection(true);
    autoscaleButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            if (autoscaleButton.getSelection()) {
                if (!autoscale) {
                    autoscale = true;
                    scaleImage();
                    drawReliefList();
                }
                minimumSpinner.setEnabled(false);
                maximumSpinner.setEnabled(false);
            } else {
                if (autoscale) {
                    autoscale = false;
                    scaleImage();
                    drawReliefList();
                }
                minimumSpinner.setEnabled(true);
                maximumSpinner.setEnabled(true);
            }
        }
    });
    Label minLabel = new Label(controlPanelComposite, SWT.NULL);
    minLabel.setText("Minimum");
    minimumSpinner = new Spinner(controlPanelComposite, SWT.NULL);
    minimumSpinner.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
    minimumSpinner.setMinimum(0);
    minimumSpinner.setMaximum(Integer.MAX_VALUE);
    minimumSpinner.setEnabled(false);
    Label maxLabel = new Label(controlPanelComposite, SWT.NULL);
    maxLabel.setText("Maximum");
    maximumSpinner = new Spinner(controlPanelComposite, SWT.NULL);
    maximumSpinner.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
    maximumSpinner.setMinimum(0);
    maximumSpinner.setMaximum(Integer.MAX_VALUE);
    maximumSpinner.setEnabled(false);
    updateButton = new Button(controlPanelComposite, SWT.NULL);
    updateButton.setText("Update");
    updateButton.setToolTipText("redraw 3d relief plot");
    updateButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            scaleImage();
            drawReliefList();
            drawRelief();
        }
    });
    Composite comp = new Composite(parent, SWT.NONE);
    comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    comp.setLayout(new FillLayout());
    GLData data = new GLData();
    data.doubleBuffer = true;
    canvas = new GLCanvas(comp, SWT.NONE, data);
    canvas.setSize(comp.getSize());
    canvas.setCurrent();
    // context =
    // GL11.GLDrawableFactory.getFactory().createExternalGLContext();
    canvas.addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event event) {
            Rectangle bounds = canvas.getBounds();
            canvas.setCurrent();
            try {
                GLContext.useContext(canvas);
            } catch (LWJGLException e) {
                e.printStackTrace();
            }
            GL11.glViewport(0, 0, bounds.width, bounds.height);
            GL11.glMatrixMode(GL11.GL_PROJECTION);
            GL11.glLoadIdentity();
            // GLU glu = new GLU();
            // aspect = (float) imageWidth / (float) imageHeight;
            // gl.glMatrixMode(GL.GL_MODELVIEW);
            // gl.glLoadIdentity();
            drawRelief();
            canvas.swapBuffers();
        }
    });
    try {
        GLContext.useContext(canvas);
    } catch (LWJGLException e) {
        e.printStackTrace();
    }

    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    GL11.glColor3f(1.0f, 0.0f, 0.0f);
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();

    // gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
    // gl.glClearDepth(1.0);
    // gl.glLineWidth(2);
    // / gl.glEnable(GL.GL_DEPTH_TEST);
    GL11.glOrtho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);

    // create the grip for users to change the orientation, translation and
    // zoom
    grip = new SceneGrip();
    canvas.addMouseListener(grip);
    canvas.addMouseMoveListener(grip);
    canvas.addListener(SWT.MouseWheel, grip);
    canvas.addKeyListener(grip);
    // apparently opengl has to be redrawn constantly (why ?)
    Display.getCurrent().asyncExec(new Runnable() {

        public void run() {
            if (!canvas.isDisposed()) {
                canvas.setCurrent();
                // Rectangle bounds = canvas.getBounds();
                /*
                 * canvasWidth = bounds.width; canvasHeight = bounds.height;
                 */
                // context.makeCurrent();
                // GL gl = context.getGL ();
                // gl.glClear(GL.GL_COLOR_BUFFER_BIT |
                // GL.GL_DEPTH_BUFFER_BIT);
                // gl.glClearColor(.0f, .0f, .0f, 1.0f); // black
                // background*/
                drawRelief();
                canvas.swapBuffers();

            }
        }
    });
}

From source file:fable.imageviewer.views.ReliefView.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {

    thisView = this;
    parent.setLayout(new GridLayout(1, false));
    GridUtils.removeMargins(parent);/*from   w w  w.j a va2 s .c  o m*/

    createActions();

    Composite comp = new Composite(parent, SWT.NONE);
    comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    comp.setLayout(new FillLayout());
    GLData data = new GLData();
    data.doubleBuffer = true;
    canvas = new GLCanvas(comp, SWT.NONE, data);
    canvas.setSize(comp.getSize());
    canvas.setCurrent();
    try {
        GLContext.useContext(canvas);
    } catch (LWJGLException ex) {
        FableUtils.excMsg(ReliefView.class, "Error in createPartControl using GLContext.useContext", ex);
    }
    // context = GLDrawableFactory.getFactory().createExternalGLContext();
    canvas.addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event event) {
            Rectangle bounds = canvas.getBounds();
            // float fAspect = (float) bounds.width / (float) bounds.height;
            canvas.setCurrent();
            try {
                GLContext.useContext(canvas);
            } catch (LWJGLException ex) {
                FableUtils.excMsg(ReliefView.class, "Error in resize listener using GLContext.useContext", ex);
            }
            // context.makeCurrent();
            // GL11 gl = context.getGL ();
            GL11.glViewport(0, 0, bounds.width, bounds.height);
            GL11.glMatrixMode(GL11.GL_PROJECTION);
            GL11.glLoadIdentity();
            // GLU glu = new GLU();
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glLoadIdentity();
            drawRelief();
            canvas.swapBuffers();
            // context.release();
        }
    });
    canvas.setCurrent();
    try {
        GLContext.useContext(canvas);
    } catch (LWJGLException ex) {
        FableUtils.excMsg(ReliefView.class, "Error in createPartControl using GLContext.useContext", ex);
    }
    // GL11 gl = context.getGL ();
    GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    GL11.glColor3f(1.0f, 0.0f, 0.0f);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
    GL11.glClearDepth(1.0);
    GL11.glLineWidth(2);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    // context.release();
    // create the grip for users to change the orientation, translation and
    // zoom
    grip = new SceneGrip(canvas, this);
    canvas.addMouseListener(grip);
    canvas.addMouseMoveListener(grip);
    canvas.addListener(SWT.MouseWheel, grip);
    canvas.addKeyListener(grip);
    // apparently opengl has to be redrawn constantly (why ?)
    Display.getCurrent().asyncExec(new Runnable() {
        // int rot = 0;
        public void run() {
            if (canvas == null)
                return;
            if (!canvas.isDisposed()) {
                canvas.setCurrent();
                Rectangle bounds = canvas.getBounds();
                grip.setBounds(bounds);
                canvas.setCurrent();
                try {
                    GLContext.useContext(canvas);
                } catch (LWJGLException ex) {
                    FableUtils.excMsg(ReliefView.class,
                            "Error in createPartControl using " + "GLContext.useContext", ex);
                }
                // GL11 gl = context.getGL ();
                GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
                GL11.glClearColor(.0f, .0f, .0f, 1.0f); // black background
                drawRelief();
                canvas.swapBuffers();
                // context.release();
                Display.getCurrent().timerExec(200, this);
            }
        }
    });

    createImageInformationPanel(parent);
}

From source file:fable.imageviewer.views.SceneGrip.java

License:Open Source License

/**
 * Warning called constantly in display loop - change with care.
 *///  ww  w  . ja v  a2 s.  c  om
public void adjust() {
    canvas.setCurrent();
    try {
        GLContext.useContext(canvas);
    } catch (LWJGLException ex) {
        FableUtils.excMsg(ReliefView.class, "Error in adjust using GLContext.useContext", ex);
    }
    // gl = context.getGL ();
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    /* set the orthogonal projection to the size of the window */
    GL11.glOrtho(0, canvasWidth, canvasHeight, 0, -1.0e5f, 1.0e5f);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
    GL11.glTranslatef(canvasWidth / 2 + this.xoff, canvasHeight / 2 + this.yoff, 0);
    GL11.glScalef(zoff, zoff, zoff);
    /*
     * zoff has no effect on the orthogonal projection therefore zoom by
     * passing zoff to scale
     */
    GL11.glRotatef(this.xrot, 1f, 0.0f, 0.0f);
    GL11.glRotatef(this.yrot, 0.0f, 1f, 0.0f);
    GL11.glTranslatef(-prov.getImageWidth() / 2, -prov.getImageHeight() / 2, 0);
}

From source file:fi.conf.ae.gl.GLGraphicRoutines.java

License:LGPL

public static void initPerspective(float angle) {
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    //GL11.glPixelZoom( 1.0f, 1.0f );
    //GL11.glViewport(0, 0, GLValues.screenWidth, GLValues.screenHeight);
    GLU.gluPerspective(angle, GLValues.glRatio, 0.001f, GLValues.glDepth);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
}

From source file:fi.conf.ae.gl.GLGraphicRoutines.java

License:LGPL

public static void initOrtho() {
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    //GL11.glPixelZoom( 1.0f, 1.0f );
    //GL11.glViewport(0, 0, GLValues.screenWidth, GLValues.screenHeight);
    GL11.glOrtho(0, GLValues.glWidth, GLValues.glHeight, 0, -GLValues.glDepth, GLValues.glDepth);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
}