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:com.mtbs3d.minecrift.VRRenderer.java

License:LGPL

private void drawMouseQuad(int mouseX, int mouseY) {
    GL11.glDisable(GL11.GL_BLEND);/*from  w w  w.  ja  va  2s .c o m*/
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glColor3f(1, 1, 1);
    this.mc.mcProfiler.endStartSection("mouse pointer");
    this.mc.getTextureManager().bindTexture(Gui.icons);
    this.mc.ingameGUI.drawTexturedModalRect(mouseX - 7, mouseY - 7, 0, 0, 16, 16);

    GL11.glEnable(GL11.GL_BLEND);
}

From source file:com.onkiup.minedroid.gui.betterfonts.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.
 *
 * @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
 *///from w  w  w.  j  a  va 2s  .  co  m
public Entry renderString(String str, int startX, int startY, int initialColor, boolean shadowFlag) {
    /* Check for invalid arguments */
    if (str == null || str.isEmpty()) {
        return null;
    }
    View.resetBlending();
    GlStateManager.enableTexture2D();
    float scale = GuiManager.getDisplayScale();
    float f = GuiManager.getScale().getScaleFactor();

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

    /* Adjust the baseline of the string because the startY coordinate in Minecraft is for the top of the string */
    startY += entry.getScaledBase();

    /* 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 */
    Tessellator tessellator = Tessellator.getInstance();
    tessellator.getWorldRenderer().startDrawingQuads();
    tessellator.getWorldRenderer().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 */
        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.
         */
        char c = str.charAt(glyph.stringIndex);
        if (c >= '0' && c <= '9') {
            int oldWidth = texture.width;
            texture = digitGlyphs[fontStyle][c - '0'].texture;
            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.getWorldRenderer().startDrawingQuads();
            tessellator.getWorldRenderer().setColorRGBA(color >> 16 & 0xff, color >> 8 & 0xff, color & 0xff,
                    color >> 24 & 0xff);

            GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.textureName);
            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
            boundTextureName = texture.textureName;
        }

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

        tessellator.getWorldRenderer().addVertexWithUV(x1, y1, 0, texture.u1, texture.v1);
        tessellator.getWorldRenderer().addVertexWithUV(x1, y2, 0, texture.u1, texture.v2);
        tessellator.getWorldRenderer().addVertexWithUV(x2, y2, 0, texture.u2, texture.v2);
        tessellator.getWorldRenderer().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.getWorldRenderer().startDrawingQuads();
        tessellator.getWorldRenderer().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 */
            Glyph glyph = entry.glyphs[glyphIndex];

            /* The strike/underlines are drawn beyond the glyph's width to include the extra space between glyphs */
            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 */
                float x1 = startX + (glyph.x - glyphSpace) / f;
                float x2 = startX + (glyph.x + glyph.advance) / f;
                float y1 = startY + (UNDERLINE_OFFSET) / f;
                float y2 = startY + (UNDERLINE_OFFSET + UNDERLINE_THICKNESS) / f;

                tessellator.getWorldRenderer().addVertex(x1, y1, 0);
                tessellator.getWorldRenderer().addVertex(x1, y2, 0);
                tessellator.getWorldRenderer().addVertex(x2, y2, 0);
                tessellator.getWorldRenderer().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 */
                float x1 = startX + (glyph.x - glyphSpace) / f;
                float x2 = startX + (glyph.x + glyph.advance) / f;
                float y1 = startY + (STRIKETHROUGH_OFFSET) / f;
                float y2 = startY + (STRIKETHROUGH_OFFSET + STRIKETHROUGH_THICKNESS) / f;

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

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

    /* Return total horizontal advance (slightly wider than the bounding box, but close enough for centering strings) */
    return entry;
}

From source file:com.rvantwisk.cnctools.controls.opengl.BeadActor.java

License:Open Source License

@Override
public void initialize() {
    ambient = allocFloats(colorDefaultDiffuse);
    diffuse = allocFloats(colorDefaultDiffuse);
    specular = allocFloats(colorDefaultSpecular);
    shininess = allocFloats(new float[] { 32.0f, 0.0f, 0.0f, 0.0f });

    light = allocFloats(colorDefaultLight);
    lightPos0 = allocFloats(lightDefaultPos0);
    lightPos1 = allocFloats(lightDefaultPos1);

    display_list = GL11.glGenLists(1);/*from w  ww .ja v  a2 s  . co m*/

    GL11.glNewList(display_list, GL11.GL_COMPILE);

    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glEnable(GL11.GL_LIGHT0);
    GL11.glEnable(GL11.GL_LIGHT1);
    GL11.glShadeModel(GL11.GL_SMOOTH);

    GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT, ambient);
    GL11.glMaterial(GL11.GL_FRONT, GL11.GL_DIFFUSE, diffuse);
    GL11.glMaterial(GL11.GL_FRONT, GL11.GL_SPECULAR, specular);
    GL11.glMaterial(GL11.GL_FRONT, GL11.GL_SHININESS, shininess);

    GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, light);
    GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, light);
    GL11.glLight(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, light);

    GL11.glLight(GL11.GL_LIGHT1, GL11.GL_POSITION, lightPos0);
    GL11.glLight(GL11.GL_LIGHT1, GL11.GL_POSITION, lightPos1);

    GL11.glColor3f(1.0f, 0.0f, 0.0f);

    Sphere s = new Sphere();
    s.setDrawStyle(GLU.GLU_FILL);
    s.setNormals(GLU.GLU_SMOOTH);
    s.draw(3.8f, 100, 100);

    GL11.glDisable(GL11.GL_LIGHT1);
    GL11.glDisable(GL11.GL_LIGHT0);
    GL11.glDisable(GL11.GL_LIGHTING);

    GL11.glEndList();

}

From source file:com.rvantwisk.cnctools.controls.opengl.OpenGLRenderer.java

License:Open Source License

protected void drawAxis(float length) {
    GL11.glPushMatrix();/*  w  ww  .  j  a  v  a 2  s.com*/
    this.viewModel.ui_transform(length + length / 2.0f);

    float[][] axis = { { length, 0.0f, 0.0f }, { 0.0f, -length, 0.0f }, { 0.0f, 0.0f, length } };
    float[][] colors = { { 1.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 0.0f, 0.5f, 1.0f } };
    String[] names = { "X", "Y", "Z" };

    GL11.glBegin(GL11.GL_LINES);
    for (int i = 0; i < 3; i++) {
        GL11.glColor3f(colors[i][0], colors[i][1], colors[i][2]);
        GL11.glVertex3f(0.0f, 0.0f, 0.0f);
        GL11.glVertex3f(axis[i][0], axis[i][1], axis[i][2]);
    }
    GL11.glEnd();

    // TODO optmize text rendering, lack of glutBitmapCharacter forces me to do it differently.
    for (int i = 0; i < 3; i++) {
        GL11.glPushMatrix();
        GL11.glColor3f(colors[i][0], colors[i][1], colors[i][2]);

        // http://breadmilkbeercigarettes.com/bmbc/shelves/users/bbb/src/java/SpinningTextureCube.php
        GL11.glTranslatef(Math.round(axis[i][0]), Math.round(axis[i][1]), Math.round(axis[i][2]));
        GL11.glRotatef(camera.getElevation() + 90f, 1.0f, 0.0f, 0.0f);
        GL11.glRotatef(-camera.getAzimuth(), 0.0f, 1.0f, 0.0f);
        SimpleText.drawString(names[i], 0.0f, 0.0f, 0.0f);

        //            GL11.glRasterPos3f(Math.round(axis[i][0]), Math.round(axis[i][1]), Math.round(axis[i][2]));
        //            SimpleText.drawString(names[i], 0, 0);

        GL11.glPopMatrix();

    }

    GL11.glPopMatrix();
}

From source file:com.samrj.devil.graphics.GraphicsUtil.java

public static void glColor(Vec3 v) {
    GL11.glColor3f(v.x, v.y, v.z);
}

From source file:com.specialeffect.gui.StateOverlay.java

License:Open Source License

private void drawScaledTextureWithGlow(ResourceLocation res, int x, int y, int width, int height) {
    GL11.glPushAttrib(GL11.GL_TEXTURE_BIT);

    this.mc.renderEngine.bindTexture(res);

    // First draw enlarged and blurred, for glow.
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);

    GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_ADD);

    // We draw the texture larger, in white, at progressive levels of alpha 
    // for blur effect (the alpha gets added on each layer)
    int blurSteps = 4; // how many levels of progressive blur
    double totalBlur = width / 12; // in pixels      
    GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f / blurSteps);

    for (int i = 0; i < blurSteps; i++) {
        double blurAmount = totalBlur / blurSteps * (i + 1);
        ModUtils.drawTexQuad(x - blurAmount, y - blurAmount, width + 2 * blurAmount, height + 2 * blurAmount);
    }//from   w  w  w.j a  va 2s .  co m

    GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_REPLACE);
    GL11.glColor3f(1.0f, 1.0f, 1.0f);
    this.mc.renderEngine.bindTexture(res);
    ModUtils.drawTexQuad(x, y, width, height);

    // reset GL attributes!
    GL11.glPopAttrib();

}

From source file:com.timvisee.voxeltex.architecture.component.drawable.line.AxisDrawComponent.java

License:Open Source License

@Override
public synchronized void onDraw() {
    // Set the thickness of the axis drawn
    GL11.glLineWidth(this.lineWidth);

    // Enable line drawing mode
    GL11.glBegin(GL11.GL_LINES);// w  ww .  j av  a 2  s  . c o  m

    // Green for X
    GL11.glColor3f(1.0f, 0.0f, 0.0f);
    GL11.glVertex3f(0.0f, 0.0f, 0.0f);
    GL11.glVertex3f(1.0f, 0.0f, 0.0f);

    // Green for Y
    GL11.glColor3f(0.0f, 1.0f, 0.0f);
    GL11.glVertex3f(0.0f, 0.0f, 0.0f);
    GL11.glVertex3f(0.0f, 1.0f, 0.0f);

    // Green for Z
    GL11.glColor3f(0.0f, 0.0f, 1.0f);
    GL11.glVertex3f(0.0f, 0.0f, 0.0f);
    GL11.glVertex3f(0.0f, 0.0f, 1.0f);

    // Finish drawing
    GL11.glEnd();
}

From source file:com.timvisee.voxeltex.architecture.component.drawable.line.GridDrawComponent.java

License:Open Source License

@Override
public synchronized void onDraw() {
    // Set the thickness of the axis drawn
    GL11.glLineWidth(this.lineWidth);

    // Enable line drawing mode
    GL11.glBegin(GL11.GL_LINES);//from ww w  . j a  v  a  2s  .c o m

    // Set the grid color
    GL11.glColor3f(0.2f, 0.2f, 0.2f);

    // Draw the grid
    for (int i = -20; i <= 20; i++) {
        GL11.glVertex3f(-20.0f, 0.0f, i);
        GL11.glVertex3f(20.0f, 0.0f, i);
        GL11.glVertex3f(i, 0.0f, -20.0f);
        GL11.glVertex3f(i, 0.0f, 20.0f);
    }

    // Finish drawing
    GL11.glEnd();
}

From source file:com.timvisee.voxeltex.module.render.RenderOverlayHelper.java

License:Open Source License

/**
 * Set the drawing color.//from  w  w w. jav  a 2  s.  c o m
 *
 * @param r Red channel intensity.
 * @param g Green channel intensity.
 * @param b Blue channel intensity.
 */
public static void color(float r, float g, float b) {
    GL11.glColor3f(r, g, b);
}

From source file:cubeItems.ModelCubeWorld.java

License:Creative Commons License

/**
 * Contrairy to as the name says, this does not render the color from the
 * model, but allows you to apply another layer of color OVER the current
 * layer. This allows e.a. greyscale models to be colored as desired.
 * /*ww  w  .  j  a  va2s .c  o  m*/
 * Has to be worked on : for now, it replaces the color, giving every cube
 * the same color
 * */
public void renderWithColor(float red, float green, float blue, float alpha) {

    glPushMatrix();
    glDisable(GL_TEXTURE_2D);
    glEnable(GL_RESCALE_NORMAL);

    final float scale = 0.0625F;
    glScalef(scale, scale, scale);
    glRotatef(-90F, 1F, 0F, 0F);

    for (int i : pointers) {
        final int x = i & 1023;
        final int y = (i >> 10) & 1023;
        final int z = (i >> 20) & 1023;

        glTranslatef(x, y, z);

        final byte[] color = modelData[x][y][z];
        glColor3ub(color[0], color[1], color[2]);

        /*
         * added this in.
         */
        GL11.glColor3f(red, green, blue);

        cube.render(1F);

        glTranslatef(-x, -y, -z);
    }

    glEnable(GL_TEXTURE_2D);
    glDisable(GL_RESCALE_NORMAL);
    glPopMatrix();
}