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:de.sanandrew.core.manpack.util.client.helpers.ItemRenderHelper.java

License:Creative Commons License

private static void renderItemIn3D(IIcon icon, boolean withEffect, int spriteIndex) {
    GL11.glPushMatrix();//from   w  ww .j  a v  a  2s  . com

    if (icon == null) {
        GL11.glPopMatrix();
        return;
    }

    float minU = icon.getMinU();
    float maxU = icon.getMaxU();
    float minV = icon.getMinV();
    float maxV = icon.getMaxV();

    Tessellator tessellator = Tessellator.instance;

    Minecraft.getMinecraft().renderEngine
            .bindTexture(Minecraft.getMinecraft().renderEngine.getResourceLocation(spriteIndex));

    GL11.glEnable(GL12.GL_RESCALE_NORMAL);

    renderItemIn2D(tessellator, maxU, minV, minU, maxV, icon.getIconWidth(), icon.getIconHeight(), 0.0625F,
            false);

    if (withEffect) {
        float baseClr = 0.76F;
        float glintScale = 0.125F;
        float glintTransX = Minecraft.getSystemTime() % 3000L / 3000.0F * 8.0F;

        GL11.glDepthFunc(GL11.GL_EQUAL);
        GL11.glDisable(GL11.GL_LIGHTING);

        Minecraft.getMinecraft().renderEngine.bindTexture(GLINT_PNG);

        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE);
        GL11.glColor4f(0.5F * baseClr, 0.25F * baseClr, 0.8F * baseClr, 1.0F);
        GL11.glMatrixMode(GL11.GL_TEXTURE);
        GL11.glPushMatrix();
        GL11.glScalef(glintScale, glintScale, glintScale);
        GL11.glTranslatef(glintTransX, 0.0F, 0.0F);
        GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F);

        renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F, false);

        GL11.glPopMatrix();
        GL11.glPushMatrix();
        GL11.glScalef(glintScale, glintScale, glintScale);

        glintTransX = Minecraft.getSystemTime() % 4873L / 4873.0F * 8.0F;

        GL11.glTranslatef(-glintTransX, 0.0F, 0.0F);
        GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F);

        renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F, false);

        GL11.glPopMatrix();
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_LIGHTING);
        GL11.glDepthFunc(GL11.GL_LEQUAL);
    }

    GL11.glDisable(GL12.GL_RESCALE_NORMAL);
    GL11.glPopMatrix();
}

From source file:de.sanandrew.core.manpack.util.client.helpers.ItemRenderHelper.java

License:Creative Commons License

/**
 * Renders an IIcon in 2D./*from   w  w  w.j a  v  a2 s .  co  m*/
 *
 * @param icon        the icon to be rendered
 * @param spriteIndex the index of the texture to be used (0 = blocks, 1 = items)
 * @param hasEffect   if it has an enchantment effect
 * @param isGlowing   if it should glow in the dark
 */
public static void renderIcon(IIcon icon, int spriteIndex, boolean hasEffect, boolean isGlowing) {
    GL11.glPushMatrix();

    if (icon == null) {
        GL11.glPopMatrix();
        return;
    }

    float minU = icon.getMinU();
    float maxU = icon.getMaxU();
    float minV = icon.getMinV();
    float maxV = icon.getMaxV();
    float transX = 0.0F;
    float transY = 0.3F;
    float scale = 1.5F;
    Tessellator tessellator = Tessellator.instance;

    Minecraft.getMinecraft().renderEngine
            .bindTexture(Minecraft.getMinecraft().renderEngine.getResourceLocation(spriteIndex));

    GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    GL11.glTranslatef(-transX, -transY, 0.0F);
    GL11.glScalef(scale, scale, scale);
    GL11.glRotatef(50.0F, 0.0F, 1.0F, 0.0F);
    GL11.glRotatef(335.0F, 0.0F, 0.0F, 1.0F);
    GL11.glTranslatef(-0.9375F, -0.0625F, 0.0F);

    renderItemIn2D(tessellator, maxU, minV, minU, maxV, icon.getIconWidth(), icon.getIconHeight(), 0.0625F,
            isGlowing);

    if (hasEffect) {
        float baseClr = 0.76F;
        float glintScale = 0.125F;
        float glintTransX = Minecraft.getSystemTime() % 3000L / 3000.0F * 8.0F;

        GL11.glDepthFunc(GL11.GL_EQUAL);
        GL11.glDisable(GL11.GL_LIGHTING);

        Minecraft.getMinecraft().renderEngine.bindTexture(GLINT_PNG);

        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE);
        GL11.glColor4f(0.5F * baseClr, 0.25F * baseClr, 0.8F * baseClr, 1.0F);
        GL11.glMatrixMode(GL11.GL_TEXTURE);
        GL11.glPushMatrix();
        GL11.glScalef(glintScale, glintScale, glintScale);
        GL11.glTranslatef(glintTransX, 0.0F, 0.0F);
        GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F);

        renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F, false);

        GL11.glPopMatrix();
        GL11.glPushMatrix();
        GL11.glScalef(glintScale, glintScale, glintScale);

        glintTransX = Minecraft.getSystemTime() % 4873L / 4873.0F * 8.0F;

        GL11.glTranslatef(-glintTransX, 0.0F, 0.0F);
        GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F);

        renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F, false);

        GL11.glPopMatrix();
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_LIGHTING);
        GL11.glDepthFunc(GL11.GL_LEQUAL);
    }

    GL11.glDisable(GL12.GL_RESCALE_NORMAL);
    GL11.glPopMatrix();
}

From source file:displayexample.DisplayExample.java

public void start() {
    x = 15;//w w  w .  j a v a2s.  co m
    y = 15;
    try {
        Display.setTitle("Exemple de fentre !");
        Display.setDisplayMode(new DisplayMode(800, 600));
        Display.create();

    } catch (LWJGLException e) {
        e.printStackTrace();
        System.exit(0);
    }
    box = new Box2D(30.0f, 50.0f, 25.0f);
    box.setUp();
    // init OpenGL here
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, 800, 0, 600, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    while (!Display.isCloseRequested() && !Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {

        // render OpenGL here

        box.draw();
        pollInput();

        Display.update();
        Display.sync(60);
    }

    Display.destroy();
    System.exit(0);
}

From source file:dripdisplay.DripDisplayLWJGL.java

protected void initGLLWJGL() {

    if (!LEVEL_EDITOR) {
        GL11.glViewport(0, 0, 800, 600);
    } else {//from   w w w . j  a v  a  2s . c  om
        GL11.glViewport(0, 0, 1000, 800);
    }
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();

    if (!LEVEL_EDITOR) {
        GL11.glOrtho(0, 800, 600, 0, 1, -1);
    } else {
        GL11.glOrtho(0, 1000, 800, 0, 1, -1);
    }
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
    initTextures();
    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    createModel();
}

From source file:edu.csun.ecs.cs.multitouchj.ui.graphic.WindowManager.java

License:Apache License

protected void initializeOpenGl() {
    DisplayMode displayMode = displayManager.getCurrentDisplayMode();

    GL11.glEnable(GL11.GL_DEPTH_TEST);//from   w w  w . j  av a2  s .co m
    GL11.glClearDepth(1.0f);
    GL11.glDepthFunc(GL11.GL_LEQUAL);

    GL11.glViewport(0, 0, displayMode.getWidth(), displayMode.getHeight());
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();

    //GLU.gluPerspective(45.0f, (float)SCREEN_WIDTH/(float)SCREEN_HEIGHT, 4.0f, 4000.0f);
    GLU.gluPerspective(45.0f, (float) displayMode.getWidth() / (float) displayMode.getHeight(), 1.0f, 100.0f);

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

    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    //GL11.glClearDepth(1.0f);

    //GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
    //GL11.glHint(GL11.GL_POLYGON_SMOOTH_HINT, GL11.GL_NICEST);

    GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glCullFace(GL11.GL_BACK);
}

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);/* w  w w . j  a v  a 2  s  .  c  o m*/
    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:edu.csun.ecs.cs.multitouchj.ui.utility.OpenGlUtility.java

License:Apache License

public static void perspectiveMode() {
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPopMatrix();/*  www . j ava2s.  co m*/
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPopMatrix();
    GL11.glEnable(GL11.GL_DEPTH_TEST);
}

From source file:eplus.renders.TableEntityItemRenderer.java

License:LGPL

/**
 * Renders a dropped item//from   w  ww  . j  a v  a 2 s . c  o  m
 */
private void renderDroppedItem(EntityItem par1EntityItem, Icon par2Icon, int par3, float par4, float par5,
        float par6, float par7) {
    Tessellator tessellator = Tessellator.instance;

    if (par2Icon == null) {
        par2Icon = this.renderManager.renderEngine
                .getMissingIcon(par1EntityItem.getEntityItem().getItemSpriteNumber());
    }

    float f4 = par2Icon.getMinU();
    float f5 = par2Icon.getMaxU();
    float f6 = par2Icon.getMinV();
    float f7 = par2Icon.getMaxV();
    float f8 = 1.0F;
    float f9 = 0.5F;
    float f10 = 0.25F;
    float f11;

    GL11.glPushMatrix();

    if (renderInFrame) {
        GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
    } else {
        GL11.glRotatef((((float) par1EntityItem.age + par4) / 20.0F + par1EntityItem.hoverStart)
                * (180F / (float) Math.PI), 0.0F, 1.0F, 0.0F);
    }

    float f12 = 0.0625F;
    f11 = 0.021875F;
    ItemStack itemstack = par1EntityItem.getEntityItem();
    int j = itemstack.stackSize;
    byte b0 = getMiniItemCount(itemstack);

    GL11.glTranslatef(-f9, -f10, -((f12 + f11) * (float) b0 / 2.0F));

    for (int k = 0; k < b0; ++k) {
        GL11.glTranslatef(0.0F, 0.0F, f12 + f11);
        // Makes items offset when in 3D, like when in 2D, looks much
        // better. Considered a vanilla bug...
        if (k > 0 && shouldSpreadItems()) {
            float x = (random.nextFloat() * 2.0F - 1.0F) * 0.3F / 0.5F;
            float y = (random.nextFloat() * 2.0F - 1.0F) * 0.3F / 0.5F;
            float z = (random.nextFloat() * 2.0F - 1.0F) * 0.3F / 0.5F;
            GL11.glTranslatef(x, y, f12 + f11);
        } else {
            GL11.glTranslatef(0f, 0f, f12 + f11);
        }

        if (itemstack.getItemSpriteNumber() == 0) {
            this.loadTexture("/terrain.png");
        } else {
            this.loadTexture("/gui/items.png");
        }

        GL11.glColor4f(par5, par6, par7, 1.0F);
        ItemRenderer.renderItemIn2D(tessellator, f5, f6, f4, f7, par2Icon.getSheetWidth(),
                par2Icon.getSheetHeight(), f12);

        if (itemstack != null && itemstack.hasEffect()) {
            GL11.glDepthFunc(GL11.GL_EQUAL);
            GL11.glDisable(GL11.GL_LIGHTING);
            this.renderManager.renderEngine.bindTexture("%blur%/misc/glint.png");
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE);
            float f13 = 0.76F;
            GL11.glColor4f(0.5F * f13, 0.25F * f13, 0.8F * f13, 1.0F);
            GL11.glMatrixMode(GL11.GL_TEXTURE);
            GL11.glPushMatrix();
            float f14 = 0.125F;
            GL11.glScalef(f14, f14, f14);
            float f15 = (float) (Minecraft.getSystemTime() % 3000L) / 3000.0F * 8.0F;
            GL11.glTranslatef(f15, 0.0F, 0.0F);
            GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F);
            ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 255, 255, f12);
            GL11.glPopMatrix();
            GL11.glPushMatrix();
            GL11.glScalef(f14, f14, f14);
            f15 = (float) (Minecraft.getSystemTime() % 4873L) / 4873.0F * 8.0F;
            GL11.glTranslatef(-f15, 0.0F, 0.0F);
            GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F);
            ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 255, 255, f12);
            GL11.glPopMatrix();
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glDisable(GL11.GL_BLEND);
            GL11.glEnable(GL11.GL_LIGHTING);
            GL11.glDepthFunc(GL11.GL_LEQUAL);
        }
    }

    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.  j  a  v a  2 s . 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:eu.over9000.veya.gui.Gui.java

License:Open Source License

private static void setUpStates(final int width, final int height) {
     try {//from  w w w . j  a  va  2s  .  com
         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);
 }