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:cn.academy.terminal.client.TerminalUI.java

License:GNU General Public License

@Override
public void draw(ScaledResolution sr) {
    //Frame update
    selection = (int) ((mouseY - 0.01) / MAX_MY * 3) * 3 + (int) ((mouseX - 0.01) / MAX_MX * 3);

    if (mouseY == 0) {
        mouseY = 1;//  www .  j a  v  a  2  s  .  c om
        if (scroll > 0)
            scroll--;
    }
    if (mouseY == MAX_MY) {
        mouseY -= 1;
        if (scroll < getMaxScroll())
            scroll++;
    }

    //Draw
    Minecraft mc = Minecraft.getMinecraft();
    long time = GameTimer.getTime();
    if (lastFrameTime == 0)
        lastFrameTime = time;
    long dt = time - lastFrameTime;

    mouseX += helper.dx * SENSITIVITY;
    mouseY -= helper.dy * SENSITIVITY;
    mouseX = Math.max(0, Math.min(MAX_MX, mouseX));
    mouseY = Math.max(0, Math.min(MAX_MY, mouseY));

    buffX = balance(dt, buffX, mouseX);
    buffY = balance(dt, buffY, mouseY);

    helper.dx = helper.dy = 0;

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

    float aspect = (float) mc.displayWidth / mc.displayHeight;
    GLU.gluPerspective(50, aspect, 1f, 100);

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

    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_ALPHA_TEST);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glColor4d(1, 1, 1, 1);

    double scale = 1.0 / 310;
    GL11.glTranslated(.35 * aspect, 1.2, -4);

    GL11.glTranslated(1, -1.8, 0);

    GL11.glRotated(-1.6, 0, 0, 1);
    GL11.glRotated(-18 - 4 * (buffX / MAX_MX - 0.5) + 1 * Math.sin(time / 1000.0), 0, 1, 0);
    GL11.glRotated(7 + 4 * (buffY / MAX_MY - 0.5), 1, 0, 0);

    //DEBUG CODE
    //        GL11.glPointSize(20);
    //        GL11.glColor4d(1, 1, 1, 1);
    //        GL11.glDisable(GL11.GL_TEXTURE_2D);
    //        GL11.glBegin(GL11.GL_POINTS);
    //        GL11.glVertex3f(0, 0, 0);
    //        GL11.glEnd();
    //        GL11.glEnable(GL11.GL_TEXTURE_2D);

    GL11.glTranslated(-1, 1.8, 0);

    GL11.glScaled(scale, -scale, scale);

    gui.draw(mouseX, mouseY);

    {
        GL11.glPushMatrix();
        double csize = (getSelectedApp() == null ? 1 : 1.3) * (20 + Math.sin(time / 300.0) * 2);
        RenderUtils.loadTexture(CURSOR);

        GL11.glColor4d(1, 1, 1, .4);
        GL11.glTranslated(0, 0, -2);
        GL11.glDisable(GL11.GL_ALPHA_TEST);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
        HudUtils.rect(-csize / 2 + buffX, -csize / 2 + buffY + 120, csize, csize);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GL11.glPopMatrix();
    }

    GL11.glPopMatrix();

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

    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glEnable(GL11.GL_ALPHA_TEST);
    GL11.glCullFace(GL11.GL_BACK);
}

From source file:cn.lambdalib.template.client.render.item.RenderModelItem.java

License:MIT License

public void renderEquipped(ItemStack item, RenderBlocks render, EntityLivingBase entity, ItemRenderType type) {

    if (item.stackTagCompound == null)
        item.stackTagCompound = new NBTTagCompound();

    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();/*w  ww  .ja va 2 s.  c o  m*/
    {
        RenderUtils.loadTexture(texturePath);
        float sc2 = 0.0625F;
        GL11.glRotatef(40F, 0, 0, 1);
        if (type == ItemRenderType.EQUIPPED)
            this.doTransformation(thirdPersonOffset);
        this.doTransformation(equipOffset);
        this.doRotation(equipRotation);
        GL11.glRotatef(90, 0, -1, 0);
        GL11.glScaled(equipScale, equipScale, equipScale);
        if (type == ItemRenderType.EQUIPPED)
            GL11.glScaled(thirdPersonScale, thirdPersonScale, thirdPersonScale);
        renderAtStdPosition(getModelAttribute(item, entity));
    }
    GL11.glPopMatrix();

}

From source file:cn.lambdalib.util.client.RenderUtils.java

License:MIT License

public static void renderOverlayEquip(ResourceLocation src) {
    //Setup//from ww w . ja  v  a2 s.  c  o m
    GL11.glDepthFunc(GL11.GL_EQUAL);
    GL11.glDisable(GL11.GL_LIGHTING);
    loadTexture(src);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE);
    float f7 = 0.76F;
    GL11.glMatrixMode(GL11.GL_TEXTURE);
    //Push texture mat
    GL11.glPushMatrix();
    float f8 = 0.125F;
    GL11.glScalef(f8, f8, f8);
    float f9 = GameTimer.getAbsTime() % 3000L / 3000.0F * 8.0F;
    GL11.glTranslatef(f9, 0.0F, 0.0F); //xOffset loops between 0.0 and 8.0
    GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F);
    ItemRenderer.renderItemIn2D(t, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F);
    GL11.glPopMatrix();

    //Second pass
    GL11.glPushMatrix();
    GL11.glScalef(f8, f8, f8);
    f9 = GameTimer.getAbsTime() % 4873L / 4873.0F * 8.0F; //Loop between 0 and 8, longer loop
    GL11.glTranslatef(-f9, 0.0F, 0.0F); //Still xOffset
    GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F); //However, different rotation!
    ItemRenderer.renderItemIn2D(t, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F);
    GL11.glPopMatrix();
    //Pop texture mat
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glDisable(GL11.GL_BLEND);
    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glDepthFunc(GL11.GL_LEQUAL);
}

From source file:cn.lambdalib.util.client.RenderUtils.java

License:MIT License

public static void renderOverlayInv(ResourceLocation src) {
    GL11.glDepthFunc(GL11.GL_EQUAL);//from w  ww .  j a v  a2s .co  m
    GL11.glDisable(GL11.GL_LIGHTING);
    loadTexture(src);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE);
    float f7 = 0.76F;
    //GL11.glColor4f(0.5F * f7, 0.25F * f7, 0.8F * f7, 1.0F);
    GL11.glMatrixMode(GL11.GL_TEXTURE);
    GL11.glPushMatrix();
    float f8 = 0.125F;
    GL11.glScalef(f8, f8, f8);
    float f9 = GameTimer.getAbsTime() % 3000L / 3000.0F * 8.0F;
    GL11.glTranslatef(f9, 0.0F, 0.0F);
    GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F);
    t.startDrawingQuads();
    t.addVertexWithUV(0.0, 0.0, 0.0, 0.0, 0.0);
    t.addVertexWithUV(0.0, 16.0, 0.0, 0.0, 1.0);
    t.addVertexWithUV(16.0, 16.0, 0.0, 1.0, 1.0);
    t.addVertexWithUV(16.0, 0.0, 0.0, 1.0, 0.0);
    t.draw();
    GL11.glPopMatrix();
    GL11.glPushMatrix();
    GL11.glScalef(f8, f8, f8);
    f9 = GameTimer.getAbsTime() % 4873L / 4873.0F * 8.0F;
    GL11.glTranslatef(-f9, 0.0F, 0.0F);
    GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F);
    t.startDrawingQuads();
    t.addVertexWithUV(0.0, 0.0, 0.0, 0.0, 0.0);
    t.addVertexWithUV(0.0, 16.0, 0.0, 0.0, 1.0);
    t.addVertexWithUV(16.0, 16.0, 0.0, 1.0, 1.0);
    t.addVertexWithUV(16.0, 0.0, 0.0, 1.0, 0.0);
    t.draw();
    GL11.glPopMatrix();
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glDisable(GL11.GL_BLEND);
    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glDepthFunc(GL11.GL_LEQUAL);
}

From source file:cn.lambdalib.util.client.RenderUtils.java

License:MIT License

public static void drawBlackout() {
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glDisable(GL11.GL_CULL_FACE);//from w ww .  java  2s .c o  m
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();
    GLU.gluOrtho2D(1, 0, 1, 0);

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

    GL11.glColor4d(0, 0, 0, 0.7);
    GL11.glTranslated(0, 0, 0);
    HudUtils.colorRect(0, 0, 1, 1);

    GL11.glPopMatrix();

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

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glColor4d(1, 1, 1, 1);

    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
}

From source file:cn.liutils.api.draw.DrawObject.java

License:Open Source License

public void draw() {
    post(EventType.PRE_DRAW);// w w w . j a  v a 2s  .c o m
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();
    {
        post(EventType.PRE_TRANSFORM);
        post(EventType.POST_TRANSFORM);
        post(EventType.PRE_TESS);
        post(EventType.DO_TESS);
        post(EventType.POST_TESS);
    }
    GL11.glPopMatrix();
    post(EventType.POST_DRAW);
}

From source file:cn.liutils.api.draw.DrawObjectList.java

License:Open Source License

@Override
public void draw() {
    postAll(EventType.PRE_DRAW);//from  w ww  . ja v a 2 s.co  m
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();
    {
        postAll(EventType.PRE_TRANSFORM);
        postAll(EventType.POST_TRANSFORM);
        postAll(EventType.PRE_TESS);
        postAll(EventType.DO_TESS);
        postAll(EventType.POST_TESS);
    }
    GL11.glPopMatrix();
    postAll(EventType.POST_DRAW);
}

From source file:cn.liutils.api.gui.Widget.java

License:Open Source License

/**
 * Should be called at this widget's draw() function.
 *///from  w w w  .j  a v a2s . c  o m
protected void drawBlackout() {

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();
    GLU.gluOrtho2D(1, 0, 1, 0);

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

    GL11.glColor4d(0, 0, 0, 0.6);
    HudUtils.setZLevel(-1);
    HudUtils.drawModalRect(0, 0, 1, 1);

    GL11.glPopMatrix();

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

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    RenderUtils.bindIdentity();

    GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
}

From source file:cn.liutils.util.render.LambdaFont.java

License:Open Source License

public void draw(String str, double x, double y, double size, Align align) {
    GL11.glEnable(GL11.GL_BLEND);/*from  ww  w.  ja  v a 2 s  .com*/
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    //GL11.glDepthMask(false);
    double psx = HudUtils.SCALE_X, psy = HudUtils.SCALE_Y;
    GL11.glPushMatrix();
    {
        GL11.glTranslated(x, y, 0);
        GL11.glScaled(size, size, 1);
        String[] ss = str.split("\n");
        for (int i = 0; i < ss.length; ++i) {
            GL11.glPushMatrix();
            {
                double dy = i * (fontSize + spacing) / fontSize;
                GL11.glTranslated(0, dy, 0);
                drawSingleLine(ss[i], align);
            }
            GL11.glPopMatrix();
        }
    }
    GL11.glPopMatrix();
    //GL11.glDepthMask(true);
    HudUtils.SCALE_X = psx;
    HudUtils.SCALE_Y = psy;
}

From source file:cn.liutils.util.render.LambdaFont.java

License:Open Source License

/**
 * It must be guaranteed that the string contains no line-break characters
 * @returns area of drawing/*  w w  w  .  j a va2s .  c  o m*/
 */
public Vector2d drawLinebreak(String str, double x, double y, double size, double cst) {
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    double psx = HudUtils.SCALE_X, psy = HudUtils.SCALE_Y;
    GL11.glPushMatrix();
    GL11.glTranslated(x, y, 0);
    GL11.glScaled(size, size, 1);

    List<Pair<String, Boolean>> arr = dlbPreProc(str, size, cst);

    double spcstp = getExtent(' ').getStep();

    double y0 = 0;
    double curLen = 0;
    double maxLen = 0;
    for (int i = 0; i < arr.size(); ++i) {
        Pair<String, Boolean> pair = arr.get(i);
        double len = widthSingleLine(pair.first);
        if (size * len < cst && size * (curLen + len) > cst) {
            --i;
            maxLen = Math.max(curLen, maxLen);
            curLen = 0;
            y0 += 1.0;
            continue;
        }

        GL11.glPushMatrix();
        {
            GL11.glTranslated(curLen, y0, 0);
            drawSingleLine(pair.first, Align.LEFT);
        }
        GL11.glPopMatrix();
        curLen += len + (pair.second ? spcstp : 0);

        if (size * len > cst) {
            maxLen = Math.max(curLen, maxLen);
            curLen = 0;
            y0 += 1.0;
        }
    }
    maxLen = Math.max(curLen, maxLen);
    GL11.glPopMatrix();
    HudUtils.SCALE_X = psx;
    HudUtils.SCALE_Y = psy;

    return new Vector2d(maxLen * size, y0 * size + size + spacing * size / fontSize);
}