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:cn.liutils.cgui.gui.component.TextBox.java

License:Open Source License

public TextBox() {
    super("TextBox");
    addEventHandler(new KeyEventHandler() {

        @Override//from w w w . java 2s.  c o  m
        public void handleEvent(Widget w, KeyEvent event) {
            if (!allowEdit)
                return;
            checkCaret();

            int par2 = event.keyCode;

            if (par2 == Keyboard.KEY_RIGHT) {
                caretPos++;
            } else if (par2 == Keyboard.KEY_LEFT) {
                caretPos--;
            }

            if (caretPos < 0)
                caretPos = 0;
            if (caretPos > content.length())
                caretPos = content.length();

            if (event.keyCode == Keyboard.KEY_V && Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) {
                String str1 = content.substring(0, caretPos), str2 = getClipboardContent(),
                        str3 = content.substring(caretPos);
                content = str1 + str2 + str3;
                w.postEvent(new ChangeContentEvent());
                return;
            }

            if (event.keyCode == Keyboard.KEY_C && Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) {
                saveClipboardContent();
                return;
            }

            if (par2 == Keyboard.KEY_BACK && content.length() > 0) {
                if (caretPos > 0) {
                    content = content.substring(0, caretPos - 1) + (caretPos == content.length() ? ""
                            : content.substring(caretPos, content.length()));
                    --caretPos;
                }
                w.postEvent(new ChangeContentEvent());
            } else if (par2 == Keyboard.KEY_RETURN || par2 == Keyboard.KEY_NUMPADENTER) {
                w.postEvent(new ConfirmInputEvent());
            } else if (par2 == Keyboard.KEY_DELETE) {
                content = "";
                w.postEvent(new ChangeContentEvent());
            }
            if (ChatAllowedCharacters.isAllowedCharacter(event.inputChar)) {
                content = content.substring(0, caretPos) + event.inputChar
                        + (caretPos == content.length() ? "" : content.substring(caretPos, content.length()));
                caretPos += 1;
                w.postEvent(new ChangeContentEvent());
            }

            checkCaret();
        }

    });

    addEventHandler(new MouseDownHandler() {
        @Override
        public void handleEvent(Widget w, MouseDownEvent event) {
            double len = 3;
            double[] offset = getOffset(w);
            double eventX = -offset[0] + event.x;

            for (int i = 0; i < content.length(); ++i) {
                double cw = Font.font.strLen(String.valueOf(content.charAt(i)), size);
                len += cw;

                if (len > eventX) {
                    caretPos = (eventX - len + cw > cw / 2) ? i + 1 : i;
                    return;
                }
            }
            caretPos = content.length();
        }
    });

    addEventHandler(new FrameEventHandler() {

        @Override
        public void handleEvent(Widget w, FrameEvent event) {

            double[] offset = getOffset(w);

            checkCaret();

            String str = getProcessedContent();

            GL11.glPushMatrix();
            GL11.glTranslated(0, 0, zLevel);

            if (emit)
                Font.font.drawTrimmed(str, offset[0], offset[1], size, color.asHexColor(), Align.LEFT,
                        w.transform.width - 2, "...");
            else
                Font.font.draw(str, offset[0], offset[1], size, color.asHexColor(), Align.LEFT);

            GL11.glPopMatrix();

            if (allowEdit && w.isFocused() && GameTimer.getAbsTime() % 1000 < 500) {
                double len = Font.font.strLen(str.substring(0, caretPos), size);
                Font.font.draw("|", len + offset[0], offset[1], size, color.asHexColor());
            }
        }

    });
}

From source file:cn.liutils.cgui.gui.LIGui.java

License:Open Source License

private void drawTraverse(double mx, double my, Widget cur, WidgetContainer set, Widget top) {
    try {/*  w w  w. java  2s.  c o m*/
        if (cur != null && cur.isVisible()) {
            GL11.glPushMatrix();
            GL11.glTranslated(cur.x, cur.y, 0);

            double px = cur.transform.pivotX * cur.scale, py = cur.transform.pivotY * cur.scale;

            GL11.glScaled(cur.scale, cur.scale, 1);
            GL11.glTranslated(-cur.transform.pivotX, -cur.transform.pivotY, 0);

            GL11.glColor4d(1, 1, 1, 1); //Force restore color for any widget
            cur.postEvent(new FrameEvent((mx - cur.x) / cur.scale, (my - cur.y) / cur.scale, cur == top));
            GL11.glPopMatrix();
        }
    } catch (Exception e) {
        LIUtils.log.error("Error occured handling widget draw. instance class: " + cur.getClass().getName()
                + ", name: " + cur.getName());
        e.printStackTrace();
    }

    if (cur == null || cur.isVisible()) {
        Iterator<Widget> iter = set.iterator();
        while (iter.hasNext()) {
            Widget wn = iter.next();
            drawTraverse(mx, my, wn, wn, top);
        }
    }
}

From source file:cn.liutils.core.client.render.RenderPlayerHook.java

License:Open Source License

@Override
public void doRender(Entity ent, double x, double y, double z, float wtf, float var9) {
    EntityPlayerHook hook = (EntityPlayerHook) ent;
    GL11.glPushMatrix();
    GL11.glTranslated(x, y, z);//from  www .  j a  v a 2s . c  om
    traverse(hook, hook.blend ? EntityPlayerHook.helpers_al : EntityPlayerHook.helpers_op);
    GL11.glPopMatrix();
}

From source file:cn.liutils.core.client.render.RenderPlayerHook.java

License:Open Source License

private void traverse(EntityPlayerHook ent, Set<IPlayerRenderHook> hooks) {
    for (IPlayerRenderHook hook : hooks) {
        GL11.glPushMatrix();
        GL11.glRotatef(ent.rotationYaw, 0.0F, -1.0F, 0.0F);
        GL11.glPushMatrix();/* ww  w  .  j  a  v a 2 s  .  c o  m*/
        {
            GL11.glTranslated(0, -1.67, 0);
            hook.renderBody(ent.player, ent.worldObj);
        }
        GL11.glPopMatrix();
        GL11.glTranslatef(0.0F, 0.5F, 0.0F);
        hook.renderHead(ent.player, ent.worldObj);
        GL11.glPopMatrix();
    }
}

From source file:cn.liutils.template.block.RenderBlockMulti.java

License:Open Source License

@Override
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float f) {
    if (!(te.getBlockType() instanceof BlockMulti))
        return;// w  w  w . j a  v  a2s  .c om

    BlockMulti bm = (BlockMulti) te.getBlockType();
    InfoBlockMulti inf = ((IMultiTile) te).getBlockInfo();

    if (inf == null || !inf.isLoaded() || inf.subID != 0)
        return;
    GL11.glPushMatrix();
    double[] off = bm.getPivotOffset(inf);
    double[] off2 = bm.rotCenters[inf.dir.ordinal()];
    GL11.glTranslated(x + off[0] + off2[0], y + 0 + off2[1], z + off[1] + off2[2]);
    //GL11.glTranslated(x, y, z);
    GL11.glRotated(bm.getRotation(inf), 0, 1, 0);
    drawAtOrigin(te);
    GL11.glPopMatrix();
}

From source file:cn.liutils.template.client.render.block.RendererSidedCube.java

License:Open Source License

public void doRender(TileEntity tileEntity, double x, double y, double z, float f) {
    Tessellator t = Tessellator.instance;
    int var5 = tileEntity.getBlockMetadata();
    block.setBlockBoundsBasedOnState(tileEntity.getWorldObj(), tileEntity.xCoord, tileEntity.yCoord,
            tileEntity.zCoord);/* w w w .j  a  v  a 2s. c  o  m*/
    setBound(block);

    Vec3 v1, v2, v3, v4, v5, v6, v7, v8;
    v1 = VecUtils.vec(minX, minY, minZ);
    v2 = VecUtils.vec(minX, minY, maxZ);
    v3 = VecUtils.vec(minX, maxY, maxZ);
    v4 = VecUtils.vec(minX, maxY, minZ);

    v5 = VecUtils.vec(maxX, minY, minZ);
    v6 = VecUtils.vec(maxX, minY, maxZ);
    v7 = VecUtils.vec(maxX, maxY, maxZ);
    v8 = VecUtils.vec(maxX, maxY, minZ);

    GL11.glPushMatrix();
    GL11.glTranslated(x, y, z);

    RenderUtils.loadTexture(getTexture(tileEntity, 4, var5));
    t.startDrawingQuads();
    t.setNormal(-1, 0, 0);
    addVertex(v1, 0, 1);
    addVertex(v2, 1, 1);
    addVertex(v3, 1, 0);
    addVertex(v4, 0, 0);
    t.draw();

    RenderUtils.loadTexture(getTexture(tileEntity, 5, var5));
    t.startDrawingQuads();
    t.setNormal(1, 0, 0);
    addVertex(v8, 1, 0);
    addVertex(v7, 0, 0);
    addVertex(v6, 0, 1);
    addVertex(v5, 1, 1);
    t.draw();

    RenderUtils.loadTexture(getTexture(tileEntity, 2, var5));
    t.startDrawingQuads();
    t.setNormal(0, 0, -1);
    addVertex(v4, 1, 0);
    addVertex(v8, 0, 0);
    addVertex(v5, 0, 1);
    addVertex(v1, 1, 1);
    t.draw();

    RenderUtils.loadTexture(getTexture(tileEntity, 3, var5));
    t.startDrawingQuads();
    t.setNormal(0, 0, 1);
    addVertex(v3, 0, 0);
    addVertex(v2, 0, 1);
    addVertex(v6, 1, 1);
    addVertex(v7, 1, 0);
    t.draw();

    RenderUtils.loadTexture(getTexture(tileEntity, 1, var5));
    t.startDrawingQuads();
    t.setNormal(0, 1, 0);
    addVertex(v3, 0, 0);
    addVertex(v7, 1, 0);
    addVertex(v8, 1, 1);
    addVertex(v4, 0, 1);
    t.draw();

    RenderUtils.loadTexture(getTexture(tileEntity, 0, var5));
    t.startDrawingQuads();
    t.setNormal(0, -1, 0);
    addVertex(v1, 0, 1);
    addVertex(v5, 1, 1);
    addVertex(v6, 1, 0);
    addVertex(v2, 0, 0);
    t.draw();

    GL11.glPopMatrix();
}

From source file:cn.liutils.template.client.render.entity.RenderModel.java

License:Open Source License

@Override
public void doRender(Entity entity, double par2, double par4, double par6, float par8, float par9) {

    GL11.glPushMatrix();
    {/*from   w w  w  .j a  v  a 2  s.  c  om*/
        bindTexture(texture);
        GL11.glTranslatef((float) par2, (float) par4 + 2 * entity.height, (float) par6);
        GL11.glTranslatef(offsetX, offsetY, offsetZ);
        GL11.glRotatef(180.0F - par8, 0.0F, 1.0F, 0.0F);
        GL11.glScalef(-1.0F, -1.0F, 1.0F);
        this.model.render(entity, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F * modelScale);
    }
    GL11.glPopMatrix();

}

From source file:cn.liutils.template.client.render.entity.RenderModelProjectile.java

License:Open Source License

@Override
public void doRender(Entity ent, double par2, double par4, double par6, float par8, float par9) {
    Motion3D motion = new Motion3D(ent);

    GL11.glPushMatrix();
    {//from   w  ww  . j a v  a 2  s .c o m
        bindTexture(TEXTURE_PATH);
        GL11.glTranslatef((float) par2, (float) par4, (float) par6);
        GL11.glRotatef(180.0F - ent.rotationYaw, 0.0F, -1.0F, 0.0F); // ?
        GL11.glRotatef(ent.rotationPitch, 1.0F, 0.0F, 0.0F); // 
        GL11.glScalef(-1.0F, -1.0F, 1.0F);
        model.render(ent, (float) par2, (float) par4, (float) par6, par8, par9, 0.0625F);
    }
    GL11.glPopMatrix();
}

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

License:Open Source License

public void renderEntityItem(RenderBlocks render, EntityItem ent) {

    GL11.glPushMatrix();
    {//from  w w  w  .j a  v a  2 s  .c om
        RenderUtils.loadTexture(texturePath);
        this.doRotation(entityItemRotation);
        GL11.glScaled(entityItemScale, entityItemScale, entityItemScale);
        renderAtStdPosition();
    }
    GL11.glPopMatrix();
}

From source file:cn.liutils.util.helper.Font.java

License:Open Source License

/**
 * Draw a string with alignment./*from   w w w  .  j  a v  a2  s  .  co m*/
 * @param str
 * @param x
 * @param y
 * @param size
 * @param color
 * @param align
 */
public void draw(String str, double x, double y, double size, int color, Align align) {
    GL11.glEnable(GL11.GL_BLEND);
    //GL11.glDepthMask(false);
    double scale = size / mcFont().FONT_HEIGHT;
    GL11.glPushMatrix();
    {
        GL11.glTranslated(x, y, 0);
        GL11.glScaled(scale, scale, 1);
        String[] ss = str.split("\n");
        for (int i = 0; i < ss.length; ++i) {
            GL11.glPushMatrix();
            {
                double dy = i * mcFont().FONT_HEIGHT;
                GL11.glTranslated(0, dy, 0);
                drawSingleLine(ss[i], color, align);
            }
            GL11.glPopMatrix();
        }
    }
    GL11.glPopMatrix();
}