Example usage for org.lwjgl.opengl GL11 glTranslated

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

Introduction

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

Prototype

public static native void glTranslated(@NativeType("GLdouble") double x, @NativeType("GLdouble") double y,
        @NativeType("GLdouble") double z);

Source Link

Document

Double version of #glTranslatef Translatef .

Usage

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

License:Open Source License

private void drawSingleLine(String line, int color, Align align) {
    double x0 = 0, y0 = 0;
    switch (align) {
    case CENTER:/*from   w ww. java2  s .c  o  m*/
        x0 = -mcFont().getStringWidth(line) / 2;
        break;
    case LEFT:
        x0 = 0;
        break;
    case RIGHT:
        x0 = -mcFont().getStringWidth(line);
        break;
    default:
        break;
    }
    GL11.glPushMatrix();
    GL11.glTranslated(x0, y0, 0);
    mcFont().drawString(line, 0, 0, color);
    GL11.glPopMatrix();
}

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

License:Open Source License

/**
 * @return Rectangle size/*w ww . j a  v  a2  s  .  c o  m*/
 */
public void drawWrapped(String str, double x, double y, double size, int color, double limit) {
    double scale = size / mcFont.FONT_HEIGHT;
    GL11.glPushMatrix();
    GL11.glTranslated(x, y, 0);
    GL11.glScaled(scale, scale, 1);
    mcFont.drawSplitString(str, 0, 0, 0xFFFFFF, (int) (limit * scale));
    GL11.glPopMatrix();
}

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

License:Open Source License

public void draw(String str, double x, double y, double size, int color, Align align) {
    GL11.glEnable(GL11.GL_BLEND);//from  w  w  w.j a va  2s . c  om
    //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();
}

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

License:Open Source License

private void drawSingleLine(String line, int color, Align align) {
    double x0 = 0, y0 = 0;
    switch (align) {
    case CENTER:/*w  w w. j  av a 2s  . com*/
        x0 = -mcFont.getStringWidth(line) / 2;
        break;
    case LEFT:
        x0 = 0;
        break;
    case RIGHT:
        x0 = -mcFont.getStringWidth(line);
        break;
    default:
        break;
    }
    GL11.glPushMatrix();
    GL11.glTranslated(x0, y0, 0);
    mcFont.drawString(line, 0, 0, color);
    GL11.glPopMatrix();
}

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  w  w  w .j av a 2  s  .co  m
    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 ww  .  ja v  a  2  s. c om*/
 */
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);
}

From source file:cn.weaponmod.api.client.render.RenderBulletWeapon.java

License:Open Source License

public static void renderMuzzleflashIn2d(Tessellator t, String texture, double tx, double ty, double tz) {

    Vec3 a1 = RenderUtils.newV3(1.2, -0.4, -0.5), a2 = RenderUtils.newV3(1.2, 0.4, -0.5),
            a3 = RenderUtils.newV3(1.2, 0.4, 0.3), a4 = RenderUtils.newV3(1.2, -0.4, 0.3);

    float u1 = 0.0F, v1 = 0.0F, u2 = 1.0F, v2 = 1.0F;

    t = Tessellator.instance;//  w  ww.  j a va2s  . c om
    GL11.glPushMatrix();
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glDisable(GL11.GL_LIGHTING);
    GL11.glDisable(GL11.GL_CULL_FACE);

    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    RenderUtils.loadTexture(texture);

    GL11.glRotatef(45, 0.0F, 0.0F, 1.0F);
    GL11.glTranslated(tx, ty + 0.1F, tz + 0.1F);

    OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240f, 240f);
    t.startDrawingQuads();
    t.setColorRGBA_F(0.8F, .8F, .8F, 1.0F);
    t.setBrightness(15728880);
    addVertex(a1, u2, v2);
    addVertex(a2, u2, v1);
    addVertex(a3, u1, v1);
    addVertex(a4, u1, v2);
    t.draw();

    GL11.glDisable(GL11.GL_BLEND);
    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glPopMatrix();

}

From source file:cn.weaponmod.api.client.render.RendererBulletWeapon.java

License:Open Source License

public static void renderMuzzleflashIn2d(Tessellator t, ResourceLocation texture, double tx, double ty,
        double tz, float size) {
    Vec3 a1 = RenderUtils.newV3(1.2, -0.4, -0.5), a2 = RenderUtils.newV3(1.2, 0.4, -0.5),
            a3 = RenderUtils.newV3(1.2, 0.4, 0.3), a4 = RenderUtils.newV3(1.2, -0.4, 0.3);

    float u1 = 0.0F, v1 = 0.0F, u2 = 1.0F, v2 = 1.0F;

    t = Tessellator.instance;//from   w ww. j  av a2 s  . c o m
    GL11.glPushMatrix();
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glDisable(GL11.GL_LIGHTING);
    GL11.glDisable(GL11.GL_CULL_FACE);

    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    RenderUtils.loadTexture(texture);

    GL11.glRotatef(45, 0.0F, 0.0F, 1.0F);
    GL11.glTranslated(tx, ty + 0.1F, tz + 0.1F);
    GL11.glScalef(size, size, size);
    OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240f, 240f);
    t.startDrawingQuads();
    t.setBrightness(15728880);
    addVertex(a1, u2, v2);
    addVertex(a2, u2, v1);
    addVertex(a3, u1, v1);
    addVertex(a4, u1, v2);
    t.draw();

    GL11.glDisable(GL11.GL_BLEND);
    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glPopMatrix();
}

From source file:cn.weaponry.impl.classic.client.animation.Muzzleflash.java

License:Open Source License

@Override
public void render(ItemInfo info, PartedModel model, boolean firstPerson) {
    double alpha = 1.0;

    if (texture == null && textures != null) {
        texture = textures[RandUtils.nextInt(textures.length)];
    }//  w w w  .ja v  a 2  s  .  c o m

    //Blend in
    long dt = getTime();
    if (dt < 40) {
        alpha = dt / 40.0;
    } else if (dt > lifeTime - 40.0) {
        alpha = (lifeTime - dt) / 40.0;
    }

    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
    GL11.glPushMatrix();
    RenderUtils.loadTexture(texture == null ? MISSING : texture);
    GL11.glTranslated(x, y, z);

    material.setTexture(texture);
    GL11.glScaled(size, size, size);
    material.color.a = alpha * 0.8;
    GL11.glRotatef(90, 0, 1, 0);
    mesh.draw(material);
    GL11.glColor4d(1, 1, 1, 1);

    GL11.glPopMatrix();
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_CULL_FACE);
}

From source file:cn.weaponry.impl.classic.client.animation.Recoil.java

License:Open Source License

@Override
public void render(ItemInfo info, PartedModel model, boolean firstPerson) {
    long time = getTime();
    double phase = time * 2 * Math.PI / recoilTime;
    double progress = (double) time / recoilTime;
    double offset = Math.sin(phase) * wiggleRadius * 1 / (1 + 8 * progress * progress * progress);

    GL11.glTranslated(recoilVec.xCoord * offset, recoilVec.yCoord * offset, 0);
}