Example usage for org.lwjgl.opengl GL11 glPushMatrix

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

Introduction

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

Prototype

public static native void glPushMatrix();

Source Link

Document

Pushes the current matrix stack down by one, duplicating the current matrix in both the top of the stack and the entry below it.

Usage

From source file:chessMod.client.ChessModDrawBlockHighlightHandler.java

License:LGPL

public static void highlightTile(EntityPlayer player, double x, double y, double z, float partialTicks) {

    x += 0.5D;/*from   www  .  j  ava2 s .c  o  m*/
    y += 0.5D;
    z += 0.5D;
    double iPX = player.prevPosX + (player.posX - player.prevPosX) * partialTicks;
    double iPY = player.prevPosY + (player.posY - player.prevPosY) * partialTicks;
    double iPZ = player.prevPosZ + (player.posZ - player.prevPosZ) * partialTicks;

    float xScale = 1.0F;
    float yScale = 1;
    float zScale = 1.0F;
    float xShift = 0.0F;
    float yShift = 0.01F;
    float zShift = 0.0F;

    GL11.glDepthMask(false);
    GL11.glDisable(GL11.GL_CULL_FACE);

    for (int i = 4; i < 5; i++) {
        ForgeDirection forgeDir = ForgeDirection.getOrientation(i);
        int zCorrection = i == 2 ? -1 : 1;
        GL11.glPushMatrix();
        GL11.glTranslated(-iPX + x + xShift, -iPY + y + yShift, -iPZ + z + zShift);
        GL11.glScalef(1F * xScale, 1F * yScale, 1F * zScale);
        GL11.glRotatef(90, forgeDir.offsetX, forgeDir.offsetY, forgeDir.offsetZ);
        GL11.glTranslated(0, 0, 0.5f * zCorrection);
        GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
        drawQuad(-0.5F, -0.5F, 1F, 1F, 0F);
        GL11.glPopMatrix();
    }

    GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glDepthMask(true);
}

From source file:cn.academy.ability.client.ui.CPBar.java

License:GNU General Public License

private void initEvents() {
    listen(FrameEvent.class, (w, e) -> {
        EntityPlayer player = Minecraft.getMinecraft().thePlayer;
        CPData cpData = CPData.get(player);
        AbilityData aData = AbilityData.get(player);
        if (!aData.hasCategory())
            return;

        Category c = aData.getCategory();
        overlayTexture = c.getOverlayIcon();

        boolean active = cpData.isActivated();

        // Calculate alpha
        long time = GameTimer.getTime();
        if (!lastFrameActive && active) {
            showTime = time;/*from ww  w . j  ava  2 s. co  m*/
        }

        // Takes account of interference
        long deltaTime = Math.min(100L, time - lastDrawTime);

        final long BLENDIN_TIME = 200L;
        mAlpha = (time - showTime < BLENDIN_TIME) ? (float) (time - showTime) / BLENDIN_TIME
                : (active ? 1.0f : Math.max(0.0f, 1 - (time - lastDrawTime) / 200.0f));

        boolean interf = cpData.isInterfering();
        boolean overloadRecovering = cpData.isOverloadRecovering();

        if (interf) {
            OffsetKeyframe frame = int_get();
            GL11.glTranslated(frame.direction.x, frame.direction.y, 0);
            long timeInput = GameTimer.getAbsTime() % maxtime;
            timeInput = (timeInput / 10) * 10; // Lower the precision to produce 'jagged' effect
            mAlpha *= alphaCurve.valueAt(timeInput);
        }

        GL11.glPushMatrix(); // PUSH 1

        float poverload = mAlpha > 0 ? cpData.getOverload() / cpData.getMaxOverload() : 0;
        bufferedOverload = balance(bufferedOverload, poverload, deltaTime * 1E-3f * O_BALANCE_SPEED);

        float pcp = mAlpha > 0 ? cpData.getCP() / cpData.getMaxCP() : 0;
        bufferedCP = balance(bufferedCP, pcp, deltaTime * 1E-3f * CP_BALANCE_SPEED);

        if (mAlpha > 0) {
            /* Draw CPBar */ {
                if (!cpData.isOverloaded()) {
                    drawNormal(bufferedOverload);
                } else {
                    drawOverload(bufferedOverload);
                }

                if (chProvider != null && !chProvider.alive())
                    chProvider = null;

                float estmCons = getConsumptionHint();
                boolean low = interf || overloadRecovering;

                if (estmCons != 0) {
                    float ncp = Math.max(0, cpData.getCP() - estmCons);

                    float oldAlpha = mAlpha;
                    mAlpha *= 0.2f + 0.1f * (1 + Math.sin(time / 80.0f));

                    drawCPBar(pcp, low);

                    mAlpha = oldAlpha;

                    drawCPBar(ncp / cpData.getMaxCP(), low);
                } else {
                    drawCPBar(bufferedCP, low);
                }
            }

            /* Draw Preset Hint */ {
                final long preset_wait = 2000L;
                if (time - presetChangeTime < preset_wait)
                    drawPresetHint((double) (time - presetChangeTime) / preset_wait, time - lastPresetTime);
            }

            // Draw data
            {
                float alpha;
                long dt = lastShowValueChange == 0 ? Long.MAX_VALUE : time - lastShowValueChange;

                if (cpData.isOverloaded()) {
                    alpha = 0.0f;
                } else if (showingNumbers) {
                    alpha = MathUtils.clampf(0, 1, (dt - 200) / 400f); // Delay display by 200ms for visual pleasure
                } else if (dt < 300f) {
                    alpha = 1 - dt / 300f;
                } else {
                    alpha = 0.0f;
                }

                if (alpha > 0) {
                    final double x0 = 110;

                    IFont font = Resources.font();
                    FontOption option = new FontOption(40);
                    option.color.a = 0.6f * mAlpha * alpha;

                    String str10 = "CP ";
                    String str11 = String.format("%.0f", cpData.getCP());
                    String str12 = String.format("/%.0f", cpData.getMaxCP());

                    String str20 = "OL ";
                    String str21 = String.format("%.0f", cpData.getOverload());
                    String str22 = String.format("/%.0f", cpData.getMaxOverload());

                    double len10 = font.getTextWidth(str10, option), len11 = font.getTextWidth(str11, option),
                            len20 = font.getTextWidth(str20, option), len21 = font.getTextWidth(str21, option);

                    double len0 = Math.max(len10, len20);
                    double len1 = len0 + Math.max(len11, len21);

                    font.draw(str10, x0, 55, option);
                    font.draw(str12, x0 + len1, 55, option);
                    font.draw(str20, x0, 85, option);
                    font.draw(str22, x0 + len1, 85, option);

                    option.align = FontAlign.RIGHT;
                    font.draw(str11, x0 + len1, 55, option);
                    font.draw(str21, x0 + len1, 85, option);
                }
            }

            drawActivateKeyHint();
        }

        if (active) {
            lastDrawTime = time;
        }

        lastFrameActive = active;

        GL11.glColor4d(1, 1, 1, 1);
        GL11.glPopMatrix(); // Pop 1
    });
}

From source file:cn.academy.ability.client.ui.KeyHintUI.java

License:GNU General Public License

private void addDrawing() {
    listen(FrameEvent.class, (w, e) -> {
        EntityPlayer player = Minecraft.getMinecraft().thePlayer;

        CPData cpData = CPData.get(player);

        canUseAbility = cpData.canUseAbility();

        long time = GameTimer.getTime();
        if (time - lastFrameTime > 300L) {
            showTime = time;//from   w  ww  . j av  a2  s  .  c o  m
        }

        if ((time - showTime) < 300L) {
            mAlpha = (time - showTime) / 300.0;
        } else {
            mAlpha = 1.0;
        }

        sinAlpha = 0.6f + (1 + MathHelper.sin((time % 100000) / 50.0f)) * 0.2f;

        if (cpData.isActivated()) {
            ClientRuntime rt = ClientRuntime.instance();
            CooldownData cd = CooldownData.of(rt.getEntity());

            Multimap<String, DelegateNode> map = rt.getDelegateRawData();
            List<String> groups = new ArrayList<>(map.keySet());
            groups.sort((s1, s2) -> {
                if (s1.equals(ClientRuntime.DEFAULT_GROUP))
                    return -1;
                else if (s2.equals(ClientRuntime.DEFAULT_GROUP))
                    return 1;
                else
                    return s1.compareTo(s2);
            });

            int availIdx = 0;
            for (int i = 0; i < groups.size(); ++i) {
                Collection<DelegateNode> nodes = map.get(groups.get(i));
                if (!nodes.isEmpty()) {
                    final double x = -200 - availIdx * 200;
                    double y = 0;
                    for (DelegateNode node : nodes) {
                        GL11.glPushMatrix();
                        GL11.glTranslated(x, y, 0);
                        drawSingle(node.keyID, node.delegate,
                                cd.getSub(node.delegate.getSkill(), node.delegate.getIdentifier()));
                        GL11.glPopMatrix();
                        y += 92;
                    }
                    availIdx++;
                }
            }
        }

        lastFrameTime = time;
        GL11.glColor4d(1, 1, 1, 1);
    });
}

From source file:cn.academy.ability.electro.client.render.skill.ChargePlaneEffect.java

License:Open Source License

@SideOnly(Side.CLIENT)
@Override//from w ww  .  ja  v  a 2s  .co  m
public void renderHud(EntityPlayer player, ScaledResolution sr, long time) {
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glDisable(GL11.GL_ALPHA_TEST);
    GL11.glDepthMask(false);
    //GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glPushMatrix();
    {
        GL11.glColor4d(1, 1, 1, 0.4);
        double w = sr.getScaledWidth_double(), h = sr.getScaledHeight_double();
        if (lct == 0 || time - lct > 200) {
            lct = time;
            seq.rebuild();
        }
        for (int i = 0; i < 4; ++i) {
            RenderUtils.loadTexture(TEXS[seq.get(i)]);
            HudUtils.drawRect(w * pts[i][0], h * pts[i][1], sizes[i] * w, sizes[i] * w);
        }
        RenderUtils.bindIdentity();
    }
    GL11.glPopMatrix();
    GL11.glDepthMask(true);
    GL11.glDisable(GL11.GL_BLEND);
    GL11.glEnable(GL11.GL_ALPHA_TEST);
}

From source file:cn.academy.ability.electro.client.render.skill.RailgunPlaneEffect.java

License:Open Source License

@SideOnly(Side.CLIENT)
@Override/* w  w w.ja  v a2 s .  c  om*/
public void renderHandEffect(EntityPlayer player, HandRenderType type, long dt) {
    if (type == HandRenderType.EQUIPPED)
        return;
    if (dt < DELAY)
        return;
    dt -= DELAY;

    double tz = dt * dt / 3e4;
    double TRANS_TIME = ANIM_LEN * 0.2;
    double alpha = (dt < TRANS_TIME ? dt / TRANS_TIME
            : (dt > ANIM_LEN - TRANS_TIME ? (ANIM_LEN - dt) / TRANS_TIME : 1));

    //Draw a screen-filling blackout
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glDisable(GL11.GL_CULL_FACE);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();
    GLU.gluOrtho2D(0, 255, 0, 255);

    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();
    GL11.glDepthMask(false);
    GL11.glLoadIdentity();
    {
        GL11.glTranslated(0, 0, 0);
        GL11.glColor4d(0, 0, 0, 0.2 * alpha);
        HudUtils.setZLevel(1);
        HudUtils.drawModalRect(0, 0, 255, 255);
        HudUtils.setZLevel(-90);
    }
    GL11.glDepthMask(true);

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

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

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glMatrixMode(GL11.GL_MODELVIEW); //Restore the matrix

    //Draw the real effect

    GL11.glColor4d(1, 1, 1, alpha * 0.6);
    GL11.glEnable(GL11.GL_ALPHA_TEST);
    GL11.glAlphaFunc(GL11.GL_GREATER, 0.0f);
    GL11.glPushMatrix();
    {
        GL11.glTranslated(-.4, 0.85 + tz * 0.37, tz);
        GL11.glRotated(-20.4, 1, 0, 0);

        drawSingleSide(7);

        //         GL11.glPushMatrix(); {
        //            GL11.glTranslated(-2.3, 0, 0);
        //            drawSingleSide(7);
        //         } GL11.glPopMatrix();
    }
    GL11.glPopMatrix();

    GL11.glDisable(GL11.GL_ALPHA_TEST);
}

From source file:cn.academy.ability.electro.client.render.skill.RailgunPlaneEffect.java

License:Open Source License

private void drawSingleSide(int n) {
    //line.draw();
    for (int i = n; i >= 0; --i) {
        double z = (4 + 6 * i * i) / 12d;
        GL11.glPushMatrix();
        GL11.glTranslated(0, 0, -z);//from w  w  w  .j  a va  2s.  c o m
        circle.draw();
        GL11.glPopMatrix();
    }
}

From source file:cn.academy.ability.electro.client.render.skill.SRSmallCharge.java

License:Open Source License

@Override
public void draw() {
    GL11.glDisable(GL11.GL_CULL_FACE);// ww  w. j a  v a2  s. com
    GL11.glDepthMask(false);
    GL11.glPushMatrix();
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glColor4d(1, 1, 1, 0.7);

    GL11.glTranslated(0, 0.9, 0.2);
    GL11.glRotated(120, 1, 0, 0);
    GL11.glScaled(0.5, 0.5, 0.5);
    //RenderUtils.drawCube(1, 1, 2);
    for (ArcObject arc : arcs) {
        arc.draw();
    }

    GL11.glPopMatrix();
    GL11.glDepthMask(true);
    GL11.glEnable(GL11.GL_CULL_FACE);
}

From source file:cn.academy.ability.teleport.client.render.entity.MarkRender.java

License:Open Source License

@Override
public void doRender(Entity ent, double x, double y, double z, float var8, float var9) {
    EntityTPMarking mark = (EntityTPMarking) ent;
    int texID = (int) ((mark.ticksExisted / 2.5) % tex.length);

    GL11.glEnable(GL11.GL_BLEND);//from   w  w w . ja  v a2s.  co m
    GL11.glDisable(GL11.GL_LIGHTING);
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glColor4d(1, 1, 1, 1);
    GL11.glPushMatrix();
    {
        GL11.glTranslated(x, y, z);

        GL11.glRotated(-mark.rotationYaw, 0, 1, 0);
        GL11.glScaled(-1, -1, 1);
        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240f, 240f);
        Tessellator.instance.setBrightness(15728880);
        RenderUtils.loadTexture(tex[texID]);
        model.draw();
    }
    GL11.glPopMatrix();
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glEnable(GL11.GL_CULL_FACE);
}

From source file:cn.academy.core.client.ACRenderingHelper.java

License:GNU General Public License

/**
 * Draws a circular progress bar at (0, 0) with radius 1
 *//*w  w w.j ava  2s.c o m*/
public static void drawCircularProgbar(ResourceLocation texture, double progress) {

    progress *= 360;
    if (progress > 360)
        progress %= 360;

    Tessellator t = Tessellator.instance;

    GL11.glPushMatrix();
    RenderUtils.loadTexture(texture);
    for (int i = 0; i < 4; ++i) {
        double angle = Math.min(90, progress - 90 * i);
        if (angle <= 0)
            break;
        double u1, v1;
        t.startDrawing(GL11.GL_TRIANGLES);

        if (angle <= 45) {
            u1 = Math.tan(MathUtils.toRadians(angle));
            v1 = 0;
        } else {
            u1 = 1;
            v1 = 0;

            double x = Math.tan(MathUtils.toRadians(90 - angle));
            t.addVertexWithUV(1, -1, 0, 1, 0);
            t.addVertexWithUV(0, 0, 0, 0, 1);
            t.addVertexWithUV(1, -x, 0, 1, 1 - x);
        }

        t.addVertexWithUV(0, -1, 0, 0, 0);
        t.addVertexWithUV(0, 0, 0, 0, 1);
        t.addVertexWithUV(u1, -1 - v1, 0, u1, v1);
        t.draw();

        GL11.glRotated(90, 0, 0, 1);
    }
    GL11.glPopMatrix();
    GL11.glEnable(GL11.GL_TEXTURE_2D);
}

From source file:cn.academy.core.client.ACRenderingHelper.java

License:GNU General Public License

private static void dirQuad(double x0, double y0, double x1, double y1, float width) {
    float hw = width / 2;
    Tessellator t = Tessellator.instance;
    double dy = y1 - y0, dx = x1 - x0, len = Math.sqrt(dy * dy + dx * dx);
    double theta = MathUtils.toDegrees(Math.atan2(dy, dx));

    GL11.glPushMatrix();
    GL11.glTranslated(x0, y0, 0);/*from  w w w  .j  a v  a 2  s.  com*/
    GL11.glRotated(theta, 0, 0, 1);
    t.startDrawingQuads();
    t.addVertexWithUV(0, -hw, 0, 0, 0);
    t.addVertexWithUV(0, hw, 0, 0, 1);
    t.addVertexWithUV(len, hw, 0, 1, 1);
    t.addVertexWithUV(len, -hw, 0, 1, 0);
    t.draw();
    GL11.glPopMatrix();
}