Example usage for org.lwjgl.opengl GL11 glBindTexture

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

Introduction

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

Prototype

public static void glBindTexture(@NativeType("GLenum") int target, @NativeType("GLuint") int texture) 

Source Link

Document

Binds the a texture to a texture target.

Usage

From source file:$.DrawSystem.java

License:Open Source License

private void drawLevel(Level level) {

        GL11.glPushMatrix();//from   w w  w . jav a  2s.c  o m
        GL11.glLoadIdentity();
        IPlay backgroundAnimationPlay = level.getBackground();
        backgroundAnimationPlay.update((long) (world.getDelta() * 1000L));
        final IAnimationFrame currentFrame = backgroundAnimationPlay.getCurrentFrame();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, (Integer) currentFrame.getImage().getId());
        float x1 = -toolkit.getVirtualResolutionWidth() / 2.0f;
        float x2 = toolkit.getVirtualResolutionWidth() / 2.0f;
        float y1 = toolkit.getVirtualResolutionHeight() / 2.0f;
        float y2 = -toolkit.getVirtualResolutionHeight() / 2.0f;
        float u1 = currentFrame.getU1();
        float u2 = currentFrame.getU2();

        float v1 = currentFrame.getV2();
        float v2 = currentFrame.getV1();
        GL11.glBegin(GL11.GL_QUADS);
        GL11.glTexCoord2f(u1, v1);
        GL11.glVertex2f(x1, y2);
        GL11.glTexCoord2f(u2, v1);
        GL11.glVertex2f(x2, y2);
        GL11.glTexCoord2f(u2, v2);
        GL11.glVertex2f(x2, y1);
        GL11.glTexCoord2f(u1, v2);
        GL11.glVertex2f(x1, y1);
        GL11.glEnd();
        GL11.glPopMatrix();
    }

From source file:$.DrawSystem.java

License:Open Source License

private void drawSprite(Sprite sprite) {
        Vector pos = spriteProjector.project(sprite.getPosition());
        final IPlay play = sprite.getPlay();
        if (null != play) {
            GL11.glPushMatrix();/*from   w  w  w.j a v a 2  s .c  o m*/
            GL11.glTranslatef(pos.x, pos.y, 0.0f);
            GL11.glRotatef(sprite.getRotate(), 0, 0, 1.0f);
            GL11.glScalef(sprite.getScale(), sprite.getScale(), 1);
            final IAnimationFrame frame = play.getCurrentFrame();
            final IAnimationImage image = frame.getImage();
            if (image.hasAlpha()) {
                GL11.glEnable(GL11.GL_BLEND);
            }
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, (Integer) image.getId());

            final float u1, u2;
            if (sprite.isMirrorX()) {
                u1 = frame.getU2();
                u2 = frame.getU1();
            } else {
                u1 = frame.getU1();
                u2 = frame.getU2();
            }

            final float v1, v2;
            if (sprite.isMirrorY()) {
                v1 = frame.getV1();
                v2 = frame.getV2();
            } else {
                v1 = frame.getV2();
                v2 = frame.getV1();
            }
            GL11.glColor4f(sprite.getRed(), sprite.getGreen(), sprite.getBlue(), sprite.getAlpha());
            float x1 = -sprite.getWidth() / 2.0f;
            float x2 = sprite.getWidth() / 2.0f;
            float y1 = -sprite.getHeight() / 2.0f;
            float y2 = sprite.getHeight() / 2.0f;
            GL11.glBegin(GL11.GL_QUADS);
            GL11.glTexCoord2f(u1, v1);
            GL11.glVertex2f(x1, y2);
            GL11.glTexCoord2f(u2, v1);
            GL11.glVertex2f(x2, y2);
            GL11.glTexCoord2f(u2, v2);
            GL11.glVertex2f(x2, y1);
            GL11.glTexCoord2f(u1, v2);
            GL11.glVertex2f(x1, y1);
            GL11.glEnd();
            GL11.glColor3f(1f, 1f, 1f);
            if (image.hasAlpha()) {
                GL11.glDisable(GL11.GL_BLEND);
            }
            GL11.glPopMatrix();
        }
        if (null != sprite.getLabel()) {
            GL11.glPushMatrix();
            GL11.glTranslatef(pos.x, pos.y, 0.0f);
            GL11.glScalef(0.5f, -0.5f, 1f);
            GL11.glEnable(GL11.GL_BLEND);
            LwjglNuitFont font = (LwjglNuitFont) assets.getFont("");
            font.drawString(sprite.getLabel(), LwjglNuitFont.Align.CENTER);
            GL11.glDisable(GL11.GL_BLEND);
            GL11.glPopMatrix();
        }
    }

From source file:a1.gui.GUI_Map.java

License:Open Source License

public void DrawTiles() {
    int x, y, i;/* w  w  w.ja v a 2s  . c o  m*/
    int stw, sth;
    Coord oc, tc, ctc, sc;

    RenderedTiles = 0;
    Render2D.ChangeColor();
    Sprite.setStaticColor();

    //   ? ?
    stw = (TILE_SIZE * 4) - 2;
    sth = TILE_SIZE * 2;
    // ?  ?
    Coord sz = scaled_size;
    oc = viewoffset(sz, mc);
    //   ? ?
    tc = mc.div(TILE_SIZE);
    tc.x += -(sz.x / (2 * stw)) - (sz.y / (2 * sth)) - 2;
    tc.y += (sz.x / (2 * stw)) - (sz.y / (2 * sth));

    if (needUpdateView) {

        needUpdateView = false;

        for (y = 0; y < (sz.y / sth) + 13; y++) {
            for (x = 0; x < (sz.x / stw) + 3; x++) {
                for (i = 0; i < 2; i++) {
                    //   
                    ctc = tc.add(new Coord(x + y, y - x + i));
                    // ?  
                    sc = m2s(ctc.mul(TILE_SIZE)).add(oc);
                    sc.x -= TILE_SIZE * 2;
                    //  
                    //    ? 
                    drawtile(ctc, sc);
                }
            }
        }

        // ?   ? 
        if (Config.tile_grid) {
            for (y = 0; y < (sz.y / sth) + 2; y++) {
                for (x = 0; x < (sz.x / stw) + 3; x++) {
                    for (i = 0; i < 2; i++) {
                        ctc = tc.add(new Coord(x + y, -x + y + i));
                        sc = m2s(ctc.mul(TILE_SIZE)).add(oc);
                        drawtile_grid(sc);
                    }
                }
            }
        }

        if (render_claims) {
            Color col;
            for (ClaimPersonal claim : Claims.claims.values()) {

                if (Player.CharID == claim.owner_id) {
                    col = new Color(0f, 1f, 1f, 0.25f);
                    //                  if (Claims.expand_claim != null)
                    //                     continue;
                } else
                    col = new Color(1f, 0f, 0f, 0.25f);

                putClaim(claim, oc, col);
            }

            if (Claims.expand_claim != null) {
                col = new Color(0f, 0f, 0.8f, 0.17f);

                putClaim(Claims.expand_claim, oc, col);
            }
        }

        //
        updateVBO();
    }

    Color.white.bind();
    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
    GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, tile_vbo);
    GL11.glVertexPointer(2, GL11.GL_FLOAT, 16, 0L);
    GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 16, 8L);

    Resource.textures.get("tiles").bind();

    GL11.glDrawArrays(GL11.GL_QUADS, 0, tile_drawCount);

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
    GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);

    if (render_claims) {
        GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, claim_vbo);
        GL11.glColorPointer(4, GL11.GL_FLOAT, 24, 0L);
        GL11.glVertexPointer(2, GL11.GL_FLOAT, 24, 16L);
        GL11.glDrawArrays(GL11.GL_QUADS, 0, claim_drawCount);
        GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
    }

    if (Config.tile_grid) {
        GL11.glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, tileGrid_vbo);
        GL11.glVertexPointer(2, GL11.GL_FLOAT, 0, 0L);
        GL11.glDrawArrays(GL11.GL_LINES, 0, tileGrid_drawCount);
    }

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);

}

From source file:a1.gui.GUI_Map.java

License:Open Source License

public void DoCreate() {
    IntBuffer tt = BufferUtils.createIntBuffer(1);
    GL11.glGenTextures(tt);/*from  w w  w. j av  a2 s .c  o m*/
    LightMap = tt.get(0);

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, LightMap);
    ByteBuffer bb = BufferUtils.createByteBuffer(1024 * 1024 * 4);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, 1024, 1024, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE,
            bb);
    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    Render2D.CheckError();
}

From source file:a1.gui.GUI_Map.java

License:Open Source License

public void RenderLightMap() {
    GL11.glBlendFunc(GL11.GL_ZERO, GL11.GL_SRC_COLOR);
    //Log.info("lightmap: "+LightMap);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, LightMap); //Resource.textures.get("core_skin").getTextureID());

    GL11.glTranslatef(0, 0, 0);//from  w  w w  .j  av a 2s  . c o  m
    GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

    float texwidth = 1024;
    float texheight = 1024;

    float newTextureOffsetX = 0 / texwidth;
    float newTextureOffsetY = 0 / texheight;
    float newTextureWidth = 1024 / texwidth;
    float newTextureHeight = 1024 / texheight;

    int w = 1024;
    int h = 1024;

    GL11.glBegin(GL11.GL_QUADS);
    {
        glTexCoord2f(newTextureOffsetX, newTextureOffsetY);
        glVertex2i(0, 0);

        glTexCoord2f(newTextureOffsetX, newTextureOffsetY + newTextureHeight);
        glVertex2i(0, h);

        glTexCoord2f(newTextureOffsetX + newTextureWidth, newTextureOffsetY + newTextureHeight);
        glVertex2i(w, h);

        glTexCoord2f(newTextureOffsetX + newTextureWidth, newTextureOffsetY);
        glVertex2i(w, 0);
    }

    GL11.glEnd();

    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
}

From source file:ar.com.quark.backend.lwjgl.opengl.DesktopGLES20.java

License:Apache License

/**
 * {@inheritDoc}
 */
@Override
public void glBindTexture(int target, int name) {
    GL11.glBindTexture(target, name);
}

From source file:armonkeykit.videocapture.QtCaptureImage.java

License:Open Source License

public boolean update(Texture texture) {

    synchronized (this) {

        if (buffer == null) {
            return false;
        }/*  w w  w  . j  a v  a  2  s.  c o m*/
        buffer.rewind();

        if (initAndScaleTexture) {
            scaleTexture(texture);
        }

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.getTextureId());
        GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, videowidth, videoheight, pixelformat, dataformat,
                buffer);

        try {
            Util.checkGLError();
        } catch (OpenGLException e) {
            log.info("Error rendering video to texture. No glTexSubImage2D/OpenGL 1.2 support?");
            System.err.println(e.getMessage());
        }

        lastupdated = framecounter;

        return true;
    }
}

From source file:betterfonts.GlyphCache.java

License:Open Source License

/**
 * Update a portion of the current glyph cache texture using the contents of the glyphCacheImage with glTexSubImage2D().
 *
 * @param dirty The rectangular region in glyphCacheImage that has changed and needs to be copied into the texture
 *
 * @todo Add mip-mapping support here/*from   ww w .jav a2s.c  o m*/
 * @todo Test with bilinear texture interpolation and possibly add a 1 pixel transparent border around each glyph to avoid
 * bleedover when interpolation is active or add a small "fudge factor" to the UV coordinates like already n FontRenderer
 */
private void updateTexture(Rectangle dirty) {
    /* Only update OpenGL texture if changes were made to the texture */
    if (dirty != null) {
        /* Load imageBuffer with pixel data ready for transfer to OpenGL texture */
        updateImageBuffer(dirty.x, dirty.y, dirty.width, dirty.height);

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureName);
        GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, dirty.x, dirty.y, dirty.width, dirty.height, GL11.GL_RGBA,
                GL11.GL_UNSIGNED_BYTE, imageBuffer);
    }
}

From source file:betterfonts.GlyphCache.java

License:Open Source License

/**
 * Allocate a new OpenGL texture for caching pre-rendered glyph images. The new texture is initialized to fully transparent
 * white so the individual glyphs images within can have a transparent border between them. The new texture remains bound
 * after returning from the function.//from www  .  j  a v  a  2  s  . co  m
 *
 * @todo use GL_ALPHA4 if anti-alias is turned off for even smaller textures
 */
private void allocateGlyphCacheTexture() {
    /* Initialize the background to all white but fully transparent. */
    glyphCacheGraphics.clearRect(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT);

    /* Allocate new OpenGL texure */
    singleIntBuffer.clear();
    GL11.glGenTextures(singleIntBuffer);
    textureName = singleIntBuffer.get(0);

    /* Load imageBuffer with pixel data ready for transfer to OpenGL texture */
    updateImageBuffer(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT);

    /*
     * Initialize texture with the now cleared BufferedImage. Using a texture with GL_ALPHA8 internal format may result in
     * faster rendering since the GPU has to only fetch 1 byte per texel instead of 4 with a regular RGBA texture.
     */
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureName);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_ALPHA8, TEXTURE_WIDTH, TEXTURE_HEIGHT, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, imageBuffer);

    /* Explicitely disable mipmap support becuase updateTexture() will only update the base level 0 */
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
}

From source file: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 x the x coordinate to draw at//w w  w . j  a  v  a 2s.  co  m
 * @param y the y coordinate to draw at
 * @param color 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(String str, int startX, int startY, int initialColor, 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 */
    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 */
    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 */
        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.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 */
        float x1 = startX + (glyphX) / 2.0F;
        float x2 = startX + (glyphX + texture.width) / 2.0F;
        float y1 = startY + (glyph.y) / 2.0F;
        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 */
            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) / 2.0F;
                float x2 = startX + (glyph.x + glyph.advance) / 2.0F;
                float y1 = startY + (UNDERLINE_OFFSET) / 2.0F;
                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 */
                float x1 = startX + (glyph.x - glyphSpace) / 2.0F;
                float x2 = startX + (glyph.x + glyph.advance) / 2.0F;
                float y1 = startY + (STRIKETHROUGH_OFFSET) / 2.0F;
                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);
    }

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