Example usage for org.lwjgl.opengl GL11 glColor3f

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

Introduction

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

Prototype

public static native void glColor3f(@NativeType("GLfloat") float red, @NativeType("GLfloat") float green,
        @NativeType("GLfloat") float blue);

Source Link

Document

Float version of #glColor3b Color3b

Usage

From source file:cellSim2.GradientWall.java

License:Open Source License

public boolean specialRender(IGL gl, Transform t) {
    if (grad == null) {
        return false;
    }//from www.  j av  a 2  s .c  o m

    //get the time 
    long ti = sim.getCurrentTimeMicroseconds();
    int axis = grad.getAxis();

    float[] wallSize = new float[3];
    getSize().get(wallSize);
    float blockSize = wallSize[axis] / (float) drawnSegments;

    float[] diagonal = new float[3];
    switch (axis) {
    case 0:
        diagonal[0] = -blockSize;
        diagonal[1] = -wallSize[1];//height
        diagonal[2] = 0;
        break;
    case 1:
        diagonal[0] = wallSize[0];//width
        diagonal[1] = blockSize;
        diagonal[2] = 0;
        break;
    case 2:
        diagonal[0] = 0;
        diagonal[1] = wallSize[1];
        diagonal[2] = blockSize;
        break;
    }
    Vector3f diagonalVector = new Vector3f(diagonal);
    //System.out.println(diagonalVector);

    float[] nextPos = new float[] { 0f, 0f, 0f };
    nextPos[axis] = blockSize;
    Vector3f nextPositionVector = new Vector3f(nextPos);
    //System.out.println(nextPositionVector);

    float[] dist = new float[] { 0f, 0f, 0f };
    dist[axis] = distanceFromSource;
    Vector3f distVector = new Vector3f(dist);

    gl.glPushMatrix();

    t.getOpenGLMatrix(glMat);
    gl.glMultMatrix(glMat);
    GL11.glNormal3f(0f, 0f, -1f);
    Vector3f vecOne = new Vector3f(startPoint);
    Vector3f vecTwo = new Vector3f(vecOne);
    vecTwo.add(diagonalVector);
    for (int i = 0; i < drawnSegments; i++) {
        //Find the concentration at this time and position
        //System.out.println("VecOne: " + vecOne + " VecTwo: " + vecTwo);
        Vector3f gradPos = new Vector3f();
        gradPos.add(vecOne, distVector);
        float[] color = grad.getColor(grad.getConcentration(ti, gradPos));
        GL11.glColor3f(color[0], color[1], color[2]);
        GL11.glBegin(GL11.GL_QUADS);
        //System.out.println(i + "ri: " + ri + " le: " + le + " con: " + con + " mi: " + mi);
        GL11.glVertex3f(vecOne.x, vecOne.y, vecOne.z);
        GL11.glVertex3f(vecTwo.x, vecOne.y, vecTwo.z);
        GL11.glVertex3f(vecTwo.x, vecTwo.y, vecTwo.z);
        GL11.glVertex3f(vecOne.x, vecTwo.y, vecOne.z);
        GL11.glEnd();
        vecOne.add(nextPositionVector);
        vecTwo.add(vecOne, diagonalVector);
        //System.out.println(startPoint + ", " + vecOne + ", " +addOnVector +", "+ vecTwo);
    }
    gl.glPopMatrix();

    return true;
    //return false;
}

From source file:cheatingessentials.mod.internal.ttf.StringCache.java

License:Open Source License

/**
 * Render a single-line string to the screen using the current OpenGL color.
 * The (x, y) coordinates are of the uppet-left corner of the string's
 * bounding box, rather than the baseline position as is typical with fonts.
 * This function will also add the string to the cache so the next
 * renderString() call with the same string is faster.
 * /*from  ww  w  .j  ava 2s  .c  om*/
 * @param str
 *            the string being rendered; it can contain color codes
 * @param startX
 *            the x coordinate to draw at
 * @param startY
 *            the y coordinate to draw at
 * @param initialColor
 *            the initial RGBA color to use when drawing the string;
 *            embedded color codes can override the RGB component
 * @param shadowFlag
 *            if true, color codes are replaces by a darker version used for
 *            drop shadows
 * @return the total advance (horizontal distance) of this string
 * @todo Add optional NumericShaper to replace ASCII digits with locale
 *       specific ones
 * @todo Add support for the "k" code which randomly replaces letters on
 *       each render (used only by splash screen)
 * @todo Pre-sort by texture to minimize binds; can store colors per glyph
 *       in string cache
 * @todo Optimize the underline/strikethrough drawing to draw a single line
 *       for each run
 */
public int renderString(final String str, final float startX, float startY, final int initialColor,
        final boolean shadowFlag) {
    /* Check for invalid arguments */
    if ((str == null) || str.isEmpty()) {
        return 0;
    }

    /*
     * Make sure the entire string is cached before rendering and return its
     * glyph representation
     */
    final Entry entry = cacheString(str);

    /*
     * Adjust the baseline of the string because the startY coordinate in
     * Minecraft is for the top of the string
     */
    startY += BASELINE_OFFSET;

    /*
     * Color currently selected by color code; reapplied to Tessellator
     * instance after glBindTexture()
     */
    int color = initialColor;

    /*
     * Track which texture is currently bound to minimize the number of
     * glBindTexture() and Tessellator.draw() calls needed
     */
    int boundTextureName = 0;

    /*
     * This color change will have no effect on the actual text (since
     * colors are included in the Tessellator vertex array), however
     * GuiEditSign of all things depends on having the current color set to
     * white when it renders its "Edit sign message:" text. Otherwise, the
     * sign which is rendered underneath would look too dark.
     */
    GL11.glColor3f((color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff);

    /*
     * Enable GL_BLEND in case the font is drawn anti-aliased because
     * Minecraft itself only enables blending for chat text (so it can fade
     * out), but not GUI text or signs. Minecraft uses multiple blend
     * functions so it has to be specified here as well for consistent
     * blending. To reduce the overhead of OpenGL state changes and making
     * native LWJGL calls, this function doesn't try to save/restore the
     * blending state. Hopefully everything else that depends on blending in
     * Minecraft will set its own state as needed.
     */
    if (antiAliasEnabled) {
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    }

    /*
     * Using the Tessellator to queue up data in a vertex array and then
     * draw all at once should be faster than immediate mode
     */
    final Tessellator tessellator = Tessellator.instance;
    tessellator.startDrawingQuads();
    tessellator.setColorRGBA((color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff, (color >> 24) & 0xff);

    /*
     * The currently active font syle is needed to select the proper ASCII
     * digit style for fast replacement
     */
    int fontStyle = Font.PLAIN;

    for (int glyphIndex = 0, colorIndex = 0; glyphIndex < entry.glyphs.length; glyphIndex++) {
        /*
         * If the original string had a color code at this glyph's position,
         * then change the current GL color that gets added to the vertex
         * array. Note that only the RGB component of the color is replaced
         * by a color code; the alpha component of the original color passed
         * into this function will remain. The while loop handles multiple
         * consecutive color codes, in which case only the last such color
         * code takes effect.
         */
        while ((colorIndex < entry.colors.length)
                && (entry.glyphs[glyphIndex].stringIndex >= entry.colors[colorIndex].stringIndex)) {
            color = applyColorCode(entry.colors[colorIndex].colorCode, initialColor, shadowFlag);
            fontStyle = entry.colors[colorIndex].fontStyle;
            colorIndex++;
        }

        /*
         * Select the current glyph's texture information and horizontal
         * layout position within this string
         */
        final Glyph glyph = entry.glyphs[glyphIndex];
        GlyphCache.Entry texture = glyph.texture;
        int glyphX = glyph.x;

        /*
         * Replace ASCII digits in the string with their respective glyphs;
         * strings differing by digits are only cached once. If the new
         * replacement glyph has a different width than the original
         * placeholder glyph (e.g. the '1' glyph is often narrower than
         * other digits), re-center the new glyph over the placeholder's
         * position to minimize the visual impact of the width mismatch.
         */
        final char c = str.charAt(glyph.stringIndex);
        if ((c >= '0') && (c <= '9')) {
            final int oldWidth = texture.width;
            texture = digitGlyphs[fontStyle][c - '0'].texture;
            final int newWidth = texture.width;
            glyphX += (oldWidth - newWidth) >> 1;
        }

        /*
         * Make sure the OpenGL texture storing this glyph's image is bound
         * (if not already bound). All pending glyphs in the Tessellator's
         * vertex array must be drawn before switching textures, otherwise
         * they would erroneously use the new texture as well.
         */
        if (boundTextureName != texture.textureName) {
            tessellator.draw();
            tessellator.startDrawingQuads();
            tessellator.setColorRGBA((color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff,
                    (color >> 24) & 0xff);

            GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.textureName);
            boundTextureName = texture.textureName;
        }

        /*
         * The divide by 2.0F is needed to align with the scaled GUI
         * coordinate system; startX/startY are already scaled
         */
        final float x1 = startX + ((glyphX) / 2.0F);
        final float x2 = startX + ((glyphX + texture.width) / 2.0F);
        final float y1 = startY + ((glyph.y) / 2.0F);
        final float y2 = startY + ((glyph.y + texture.height) / 2.0F);

        tessellator.addVertexWithUV(x1, y1, 0, texture.u1, texture.v1);
        tessellator.addVertexWithUV(x1, y2, 0, texture.u1, texture.v2);
        tessellator.addVertexWithUV(x2, y2, 0, texture.u2, texture.v2);
        tessellator.addVertexWithUV(x2, y1, 0, texture.u2, texture.v1);
    }

    /*
     * Draw any remaining glyphs in the Tessellator's vertex array (there
     * should be at least one glyph pending)
     */
    tessellator.draw();

    /* Draw strikethrough and underlines if the string uses them anywhere */
    if (entry.specialRender) {
        int renderStyle = 0;

        /*
         * Use initial color passed to renderString(); disable texturing to
         * draw solid color lines
         */
        color = initialColor;
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        tessellator.startDrawingQuads();
        tessellator.setColorRGBA((color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff, (color >> 24) & 0xff);

        for (int glyphIndex = 0, colorIndex = 0; glyphIndex < entry.glyphs.length; glyphIndex++) {
            /*
             * If the original string had a color code at this glyph's
             * position, then change the current GL color that gets added to
             * the vertex array. The while loop handles multiple consecutive
             * color codes, in which case only the last such color code
             * takes effect.
             */
            while ((colorIndex < entry.colors.length)
                    && (entry.glyphs[glyphIndex].stringIndex >= entry.colors[colorIndex].stringIndex)) {
                color = applyColorCode(entry.colors[colorIndex].colorCode, initialColor, shadowFlag);
                renderStyle = entry.colors[colorIndex].renderStyle;
                colorIndex++;
            }

            /*
             * Select the current glyph within this string for its layout
             * position
             */
            final Glyph glyph = entry.glyphs[glyphIndex];

            /*
             * The strike/underlines are drawn beyond the glyph's width to
             * include the extra space between glyphs
             */
            final int glyphSpace = glyph.advance - glyph.texture.width;

            /* Draw underline under glyph if the style is enabled */
            if ((renderStyle & ColorCode.UNDERLINE) != 0) {
                /*
                 * The divide by 2.0F is needed to align with the scaled GUI
                 * coordinate system; startX/startY are already scaled
                 */
                final float x1 = startX + ((glyph.x - glyphSpace) / 2.0F);
                final float x2 = startX + ((glyph.x + glyph.advance) / 2.0F);
                final float y1 = startY + ((UNDERLINE_OFFSET) / 2.0F);
                final float y2 = startY + ((UNDERLINE_OFFSET + UNDERLINE_THICKNESS) / 2.0F);

                tessellator.addVertex(x1, y1, 0);
                tessellator.addVertex(x1, y2, 0);
                tessellator.addVertex(x2, y2, 0);
                tessellator.addVertex(x2, y1, 0);
            }

            /*
             * Draw strikethrough in the middle of glyph if the style is
             * enabled
             */
            if ((renderStyle & ColorCode.STRIKETHROUGH) != 0) {
                /*
                 * The divide by 2.0F is needed to align with the scaled GUI
                 * coordinate system; startX/startY are already scaled
                 */
                final float x1 = startX + ((glyph.x - glyphSpace) / 2.0F);
                final float x2 = startX + ((glyph.x + glyph.advance) / 2.0F);
                final float y1 = startY + ((STRIKETHROUGH_OFFSET) / 2.0F);
                final float y2 = startY + ((STRIKETHROUGH_OFFSET + STRIKETHROUGH_THICKNESS) / 2.0F);

                tessellator.addVertex(x1, y1, 0);
                tessellator.addVertex(x1, y2, 0);
                tessellator.addVertex(x2, y2, 0);
                tessellator.addVertex(x2, y1, 0);
            }
        }

        /* Finish drawing the last strikethrough/underline segments */
        tessellator.draw();
        GL11.glEnable(GL11.GL_TEXTURE_2D);
    }

    if (antiAliasEnabled) {
        GL11.glDisable(GL11.GL_BLEND);
    }
    /*
     * Return total horizontal advance (slightly wider than the bounding
     * box, but close enough for centering strings)
     */
    return entry.advance / 2;
}

From source file:cn.academy.core.client.render.RenderVoid.java

License:Open Source License

public static final void renderHand(EntityPlayer player) {

    GL11.glDisable(GL11.GL_CULL_FACE);/*from w w w.j av  a 2s .  com*/
    GL11.glPushMatrix();

    RenderUtils.renderEnchantGlint_Equip();
    RenderUtils.loadTexture(steveTexture);
    GL11.glRotated(-23.75, 0.0F, 0.0F, 1.0F);
    GL11.glRotated(21.914, 0.0F, 1.0F, 0.0F);
    GL11.glRotated(32.75, 1.0F, 0.0F, 0.0F);
    GL11.glTranslatef(.758F, -.072F, -.402F);
    GL11.glColor3f(1.0F, 1.0F, 1.0F);

    model.onGround = 0.0F;
    model.setRotationAngles(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F, player);
    model.bipedRightArm.render(0.0625F);

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

From source file:cn.lambdacraft.crafting.block.crafter.GuiWeaponCrafter.java

License:Open Source License

@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
    GL11.glColor3f(1.0F, 1.0F, 1.0F);

    //Text draw// w  ww .  j  a  va2 s  .com
    String storage = StatCollector.translateToLocal("gui.crafter_storage.name"),
            currentPage = StatCollector.translateToLocal(RecipeWeapons.getPageDescription(te.currentPage));

    this.fontRendererObj.drawString(storage, 8, 88, 0x3a3531);
    fontRendererObj.drawString(currentPage, 100 - fontRendererObj.getStringWidth(currentPage) / 2, 1, 0x3a3531);

    super.drawGuiContainerForegroundLayer(par1, par2);
}

From source file:cn.lambdacraft.crafting.client.gui.GuiWeaponCrafter.java

License:Open Source License

@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
    GL11.glColor3f(1.0F, 1.0F, 1.0F);
    String storage = StatCollector.translateToLocal("gui.crafter_storage.name");
    String currentPage = StatCollector.translateToLocal(RecipeWeapons.getDescription(te.page));
    this.fontRenderer.drawString(storage, 8, 88, 4210752);
    fontRenderer.drawString(currentPage, 100 - fontRenderer.getStringWidth(currentPage) / 2, 1, 4210752);
    super.drawGuiContainerForegroundLayer(par1, par2);
}

From source file:cn.lambdacraft.mob.client.renderer.RenderBarnacle.java

License:Open Source License

@Override
public void doRender(Entity entity, double par2, double par4, double par6, float par8, float par9) {
    EntityBarnacle barnacle = (EntityBarnacle) entity;
    Tessellator t = Tessellator.instance;
    GL11.glPushMatrix();/*  ww w. j av a2s  .  c  o  m*/
    Minecraft.getMinecraft().renderEngine.bindTexture(ClientProps.BARNACLE_PATH);
    GL11.glTranslatef((float) par2, (float) par4 + 2 * entity.height, (float) par6);
    GL11.glScalef(-1.0F, -1.0F, 1.0F);
    GL11.glTranslatef(0.0F, 1.5F, 0.0F);
    if (barnacle.getHealth() <= 0)
        GL11.glRotatef(barnacle.deathTime * 6.5F, 1.0F, 0.0F, -1.0F);
    GL11.glTranslatef(0.0F, -1.5F, 0.0F);
    if (barnacle.hurtResistantTime > 10)
        GL11.glColor3f(1.0F, 0.5F, 0.5F);

    this.model.render(entity, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);

    if (barnacle.getHealth() > 0) {
        //Barnacle Tentacle Render
        double length = barnacle.tentacleLength;
        double h1 = 0.5, h2 = length + 1.0;
        Vec3 v1 = RenderUtils.newV3(-WIDTH, h1, -WIDTH), v2 = RenderUtils.newV3(-WIDTH, h1, WIDTH),
                v3 = RenderUtils.newV3(WIDTH, h1, WIDTH), v4 = RenderUtils.newV3(WIDTH, h1, -WIDTH);
        Vec3 v5 = RenderUtils.newV3(-WIDTH, h1, -WIDTH), v6 = RenderUtils.newV3(-WIDTH, h2, WIDTH),
                v7 = RenderUtils.newV3(WIDTH, h2, WIDTH), v8 = RenderUtils.newV3(WIDTH, h2, -WIDTH);
        Minecraft.getMinecraft().renderEngine.bindTexture(ClientProps.BARNACLE_TENTACLE_PATH);

        t.startDrawingQuads();
        RenderUtils.addVertex(v1, 0.0, 0.0);
        RenderUtils.addVertex(v5, 0.0, length);
        RenderUtils.addVertex(v6, 1.0, length);
        RenderUtils.addVertex(v2, 1.0, 0.0);

        RenderUtils.addVertex(v2, 0.0, 0.0);
        RenderUtils.addVertex(v6, 0.0, length);
        RenderUtils.addVertex(v7, 1.0, length);
        RenderUtils.addVertex(v3, 1.0, 0.0);

        RenderUtils.addVertex(v3, 0.0, 0.0);
        RenderUtils.addVertex(v7, 0.0, length);
        RenderUtils.addVertex(v8, 1.0, length);
        RenderUtils.addVertex(v4, 1.0, 0.0);

        RenderUtils.addVertex(v4, 0.0, 0.0);
        RenderUtils.addVertex(v8, 0.0, length);
        RenderUtils.addVertex(v5, 1.0, length);
        RenderUtils.addVertex(v1, 1.0, 0.0);

        RenderUtils.addVertex(v8, 0.0, 0.0);
        RenderUtils.addVertex(v7, 0.0, 0.1);
        RenderUtils.addVertex(v6, 0.1, 0.1);
        RenderUtils.addVertex(v5, 0.1, 0.0);
        t.draw();
    }
    GL11.glColor3f(1.0F, 1.0F, 1.0F);
    GL11.glPopMatrix();
}

From source file:cn.lambdacraft.mob.client.renderer.RenderTurret.java

License:Open Source License

@Override
public void doRender(Entity entity, double par2, double par4, double par6, float par8, float f1) {
    EntitySentry turret = (EntitySentry) entity;
    GL11.glPushMatrix();/*from   ww w .  j a  v  a  2s  .c  o m*/
    GL11.glDisable(GL11.GL_CULL_FACE);
    RenderUtils.loadTexture(ClientProps.TURRET_PATH);
    super.doRender(entity, par2, par4, par6, par8, f1);
    GL11.glTranslatef((float) par2, (float) par4 + turret.height - turret.deathTime * 0.06F, (float) par6);
    GL11.glScalef(-1.0F, -1.0F, 1.0F);
    if (turret.hurtResistantTime > 15)
        GL11.glColor3f(1.0F, 0.3F, 0.3F);
    GL11.glRotatef(turret.deathTime * 3, 1.0F, 0.2F, -1.0F);
    GL11.glRotatef(180.0F - turret.rotationYawHead, 0.0F, 1.0F, 0.0F);
    model.renderTop(entity, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
    GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glPopMatrix();
}

From source file:cn.lambdalib.template.client.render.entity.RenderCrossedProjectile.java

License:MIT License

@Override
public void doRender(Entity entity, double par2, double par4, double par6, float par8, float par9) {
    Motion3D motion = new Motion3D(entity);
    Tessellator t = Tessellator.instance;

    GL11.glPushMatrix();//from   w w w .  j a  v a 2  s  . co m
    {
        Vec3 v1 = newV3(0, HEIGHT, 0), v2 = newV3(0, -HEIGHT, 0), v3 = newV3(LENGTH, -HEIGHT, 0),
                v4 = newV3(LENGTH, HEIGHT, 0), v5 = newV3(0, 0, -HEIGHT), v6 = newV3(0, 0, HEIGHT),
                v7 = newV3(LENGTH, 0, HEIGHT), v8 = newV3(LENGTH, 0, -HEIGHT);

        GL11.glDisable(GL11.GL_CULL_FACE);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

        if (renderTexture) {
            bindTexture(TEXTURE_PATH);
        } else {
            GL11.glDisable(GL11.GL_TEXTURE_2D);
            GL11.glColor3f(colorR, colorG, colorB);
        }
        if (ignoreLight) {
            GL11.glDisable(GL11.GL_LIGHTING);
            OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240f, 240f);
        }

        GL11.glTranslatef((float) par2, (float) par4, (float) par6);

        GL11.glRotatef(90 + entity.rotationYaw, 0.0F, -1.0F, 0.0F); // ?
        GL11.glRotatef(-entity.rotationPitch, 0.0F, 0.0F, 1.0F); // 

        if (this.playerViewOptm) {
            boolean firstPerson = Minecraft.getMinecraft().gameSettings.thirdPersonView == 0;
            if (firstPerson) {
                GL11.glTranslated(fpOffsetX, fpOffsetY, fpOffsetZ);
            } else {
                GL11.glTranslated(tpOffsetX, tpOffsetY, tpOffsetZ);
            }
        }

        t.startDrawingQuads();
        if (ignoreLight)
            t.setBrightness(15728880);

        RenderUtils.addVertex(v1, 0, 0);
        RenderUtils.addVertex(v2, 0, 1);
        RenderUtils.addVertex(v3, 1, 1);
        RenderUtils.addVertex(v4, 1, 0);

        RenderUtils.addVertex(v5, 0, 0);
        RenderUtils.addVertex(v6, 0, 1);
        RenderUtils.addVertex(v7, 1, 1);
        RenderUtils.addVertex(v8, 1, 0);

        t.draw();

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

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

License:MIT License

public static void renderEnchantGlintEquip() {
    GL11.glColor3f(0.301F, 0.78F, 1.0F);
    renderOverlayEquip(src_glint);
}

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

License:MIT License

public static void renderEnchantGlintInv() {
    GL11.glColor3f(0.301F, 0.78F, 1.0F);
    renderOverlayInv(src_glint);
}