Example usage for org.lwjgl.opengl GL11 glMatrixMode

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

Introduction

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

Prototype

public static native void glMatrixMode(@NativeType("GLenum") int mode);

Source Link

Document

Set the current matrix mode.

Usage

From source file:net.smert.frameworkgl.opengl.OpenGL1.java

License:Apache License

public OpenGL1 setProjectionPerspective(float fovy, float aspectratio, float zNear, float zFar) {
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    matrix.setPerspective(fovy, aspectratio, zNear, zFar).toFloatBuffer(matrixBuffer);
    matrixBuffer.flip();//from   w  w  w  .j  av  a  2 s.c  o m
    loadMatrix(matrixBuffer);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
    return this;
}

From source file:net.smert.frameworkgl.opengl.OpenGL1.java

License:Apache License

public OpenGL1 switchModelView() {
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    return this;
}

From source file:net.smert.frameworkgl.opengl.OpenGL1.java

License:Apache License

public OpenGL1 switchProjection() {
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    return this;
}

From source file:org.agpu.oc.common.tileentity.AdvancedMonitor.java

public void startDrawing3D(int x, int y, int width, int height, float fov, float zNear, float zFar) {
    if (worldObj.isRemote) {
        GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBufferID);

        GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
        GL11.glViewport(0, 0, width, height);

        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glPushMatrix();// www  .ja  va 2 s.  c om
        GL11.glLoadIdentity();
        GLU.gluPerspective(fov, (float) width / (float) height, zNear, zFar);

        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glPushMatrix();
        GL11.glLoadIdentity();

        GL11.glClearColor(cr, cg, cb, ca);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    }
}

From source file:org.agpu.oc.common.tileentity.AdvancedMonitor.java

public void startDrawing2D(int x, int y, int width, int height) {
    if (worldObj.isRemote) {
        GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBufferID);

        GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
        GL11.glViewport(x, y, width, height);

        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glPushMatrix();/* ww  w.j av a2  s. com*/
        GL11.glLoadIdentity();
        GL11.glOrtho(0, width, height, 0, 1, -1);

        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glPushMatrix();
        GL11.glLoadIdentity();

        GL11.glClearColor(cr, cg, cb, ca);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    }
}

From source file:org.agpu.oc.common.tileentity.AdvancedMonitor.java

public void swapBuffers(NBTTagCompound tag) {
    if (worldObj.isRemote) {
        for (int i = 0; i < tag.getInteger("commands"); i++) {
            NBTTagCompound t = tag.getCompoundTag(String.valueOf(i));
            String type = t.getString("type");
            if (type.equals("startDrawing3D")) {
                startDrawing3D(t.getInteger("x"), t.getInteger("y"), t.getInteger("width"),
                        t.getInteger("height"), t.getFloat("fov"), t.getFloat("zNear"), t.getFloat("zFar"));
            } else if (type.equals("startDrawing2D")) {
                startDrawing2D(t.getInteger("x"), t.getInteger("y"), t.getInteger("width"),
                        t.getInteger("height"));
            } else if (type.equals("setColor")) {
                GL11.glColor4f(t.getFloat("r"), t.getFloat("g"), t.getFloat("b"), t.getFloat("a"));
            } else if (type.equals("vertex3f")) {
                GL11.glVertex3f(t.getFloat("x"), t.getFloat("y"), t.getFloat("z"));
            } else if (type.equals("vertex2i")) {
                GL11.glVertex2i(t.getInteger("x"), t.getInteger("y"));
            } else if (type.equals("translate")) {
                GL11.glTranslatef(t.getFloat("x"), t.getFloat("y"), t.getFloat("z"));
            } else if (type.equals("rotate")) {
                GL11.glRotatef(t.getFloat("angle"), t.getFloat("x"), t.getFloat("y"), t.getFloat("z"));
            } else if (type.equals("scale")) {
                GL11.glScalef(t.getFloat("x"), t.getFloat("y"), t.getFloat("z"));
            } else if (type.equals("begin")) {
                GL11.glBegin(t.getInteger("m"));
            } else if (type.equals("end")) {
                GL11.glEnd();//w ww.j  a va2  s.  c o  m
            } else if (type.equals("string")) {
                Minecraft.getMinecraft().fontRendererObj.drawString(t.getString("string"), t.getInteger("x"),
                        t.getInteger("y"), t.getInteger("color"));
            } else if (type.equals("enable")) {
                GL11.glEnable(t.getInteger("v"));
            } else if (type.equals("disable")) {
                GL11.glDisable(t.getInteger("v"));
            } else {
                System.out.println("Unknown packet type received: " + type);
            }
        }

        GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);

        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glPopMatrix();

        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glPopMatrix();
        GL11.glPopAttrib();
    }
}

From source file:org.cogaen.lwjgl.scene.Camera.java

License:Open Source License

void applyTransform() {
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();/*  w w w  . j av a 2 s .  c  om*/
    GL11.glOrtho(0, this.width, 0, this.height, 1, -1);
    GL11.glTranslated(this.width / 2, this.height / 2, 0.0);

    GL11.glScaled(this.zoom, this.zoom, 0.0);
    GL11.glRotatef((float) -this.angle, 0, 0, 1);
    GL11.glTranslated(-this.posX, -this.posY, 0);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glViewport(this.viewport.getX(), this.viewport.getY(), this.viewport.getWidth(),
            this.viewport.getHeight());
}

From source file:org.cogaen.lwjgl.scene.SceneService.java

License:Open Source License

public void renderScene() {

    // quite and dirty frame counter
    this.clock.tick();
    this.fpsSum += this.clock.getDelta();
    if (++this.fpsCnt >= this.fpsAvg) {
        this.fpsCnt = 0;
        this.fps = String.format("FPS: %2.2f", (1.0 / (this.fpsSum / this.fpsAvg)));
        this.fpsSum = 0.0;
    }/*w w w . ja v a 2  s.c  o m*/

    // Clear the screen and depth buffer
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

    // render layers in each camera
    for (Camera camera : cameras) {
        if (!camera.isActive()) {
            continue;
        }

        camera.applyTransform();
        for (int i = this.layers.size() - 1; i >= 0; --i) {
            this.layers.get(i).render(camera.getMask());
        }

        for (RenderSubsystem rs : this.subSystems) {
            rs.render(camera.getMask());
        }
    }

    // draw overlays
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, 1.0, 0, 1.0 / getAspectRatio(), 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glViewport(0, 0, this.config.getWidth(), this.config.getHeight());

    this.overlayRoot.renderWithAspectRatio(0xFFFFFFFF, getAspectRatio());
    //      this.overlayRoot.render(0xFFFFFFFF);

    // render frame counter
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, this.config.getWidth(), this.config.getHeight(), 0, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glColor4d(1, 0, 1, 1);
    font.drawString(5, this.config.getHeight() - 20, this.fps);

    Display.update();

    if (Display.isCloseRequested()) {
        this.evtSrv.dispatchEvent(new SimpleEvent(WINDOW_CLOSE_REQUEST));
    }
}

From source file:org.eclipse.swt.opengl.examples.LWJGLExample.java

License:Open Source License

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  www .  j a  va  2s  .  com
    final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data);

    canvas.setCurrent();
    try {
        GLContext.useContext(canvas);
    } catch (LWJGLException e) {
        e.printStackTrace();
    }

    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 e) {
                e.printStackTrace();
            }
            GL11.glViewport(0, 0, bounds.width, bounds.height);
            GL11.glMatrixMode(GL11.GL_PROJECTION);
            GL11.glLoadIdentity();
            GLU.gluPerspective(45.0f, fAspect, 0.5f, 400.0f);
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glLoadIdentity();
        }
    });

    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);

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

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

        public void run() {
            if (!canvas.isDisposed()) {
                canvas.setCurrent();
                try {
                    GLContext.useContext(canvas);
                } catch (LWJGLException e) {
                    e.printStackTrace();
                }
                GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
                GL11.glClearColor(.3f, .5f, .8f, 1.0f);
                GL11.glLoadIdentity();
                GL11.glTranslatef(0.0f, 0.0f, -10.0f);
                float frot = rot;
                GL11.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f);
                GL11.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f);
                rot++;
                GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
                GL11.glColor3f(0.9f, 0.9f, 0.9f);
                drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15);
                canvas.swapBuffers();
                display.asyncExec(this);
            }
        }
    });

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

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

License:Open Source License

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;/*  www.j a  va2 s  . c o  m*/
    final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data);

    canvas.setCurrent();
    try {
        GLContext.useContext(canvas);
    } catch (LWJGLException e) {
        e.printStackTrace();
    }

    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();
            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.gluPerspective(45.0f, fAspect, 0.5f, 400.0f);
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glLoadIdentity();
        }
    });

    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);

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

    final Runnable run = new Runnable() {
        int rot = 0;

        @Override
        public void run() {
            if (!canvas.isDisposed()) {
                canvas.setCurrent();
                try {
                    GLContext.useContext(canvas);
                } catch (LWJGLException e) {
                    e.printStackTrace();
                }
                GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
                GL11.glClearColor(.3f, .5f, .8f, 1.0f);
                GL11.glLoadIdentity();
                GL11.glTranslatef(0.0f, 0.0f, -10.0f);
                float frot = rot;
                GL11.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f);
                GL11.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f);
                rot++;
                GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
                GL11.glColor3f(0.9f, 0.9f, 0.9f);
                drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15);
                canvas.swapBuffers();
                display.asyncExec(this);
            }
        }
    };
    canvas.addListener(SWT.Paint, new Listener() {
        @Override
        public void handleEvent(Event event) {
            run.run();
        }
    });
    display.asyncExec(run);

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