Example usage for org.lwjgl.opengl GL11 glTexCoord2f

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

Introduction

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

Prototype

public static native void glTexCoord2f(@NativeType("GLfloat") float s, @NativeType("GLfloat") float t);

Source Link

Document

Sets the current two-dimensional texture coordinate.

Usage

From source file:$.DrawSystem.java

License:Open Source License

private void drawLevel(Level level) {

        GL11.glPushMatrix();// w w  w .  j av a  2 s.  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   ww  w.j  a  v a  2  s. co  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:ai.UnitAI.java

License:Open Source License

public void draw() {
    icon.bind();//from ww w.j a  v a2s  .c o  m
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(0, 0);
    GL11.glVertex2i(0, 0);
    GL11.glTexCoord2f(0, 1);
    GL11.glVertex2i(0, 64);
    GL11.glTexCoord2f(1, 1);
    GL11.glVertex2i(64, 64);
    GL11.glTexCoord2f(1, 0);
    GL11.glVertex2i(64, 0);
    GL11.glEnd();
}

From source file:cn.academy.crafting.client.render.item.RendererMatterUnit.java

License:GNU General Public License

@Override
public void renderItem(ItemRenderType type, ItemStack stack, Object... data) {
    ItemMatterUnit item = ModuleCrafting.matterUnit;
    GL11.glColor4d(1, 1, 1, 1);//from  w w  w .j a  v  a2 s.c o  m
    if (type != ItemRenderType.INVENTORY) {
        GL11.glPushMatrix();
        {
            if (type == ItemRenderType.ENTITY)
                GL11.glTranslated(-.5, -0.1, 0);

            RenderUtils.drawEquippedItem(stack, 0.0625f);

            GL11.glColorMask(false, false, false, false);
            RenderUtils.drawEquippedItem(0.0626f, texMask, texMask);
            GL11.glColorMask(true, true, true, true);

            GL11.glDepthFunc(GL11.GL_EQUAL);
            MatterMaterial mat = item.getMaterial(stack);
            RenderUtils.drawEquippedItemOverlay(0.0626f, mat.texture);
            GL11.glDepthFunc(GL11.GL_LEQUAL);
        }
        GL11.glPopMatrix();
    } else {
        ShaderMask shader = ShaderMask.instance;
        float du = -(GameTimer.getAbsTime() % 10000L) / 1e4f, dv = (GameTimer.getAbsTime() % 10000L) / 1e4f;

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

        RenderUtils.renderItemInventory(stack);

        shader.start(texMask);
        RenderUtils.loadTexture(item.getMaterial(stack).texture);

        GL11.glBegin(GL11.GL_QUADS);

        GL11.glTexCoord2f(0 + du, 0 + dv);
        shader.maskTexCoord(0, 0);
        GL11.glVertex2f(0, 0);

        GL11.glTexCoord2f(0 + du, 1 + dv);
        shader.maskTexCoord(0, 1);
        GL11.glVertex2f(0, 16);

        GL11.glTexCoord2f(1 + du, 1 + dv);
        shader.maskTexCoord(1, 1);
        GL11.glVertex2f(16, 16);

        GL11.glTexCoord2f(1 + du, 0 + dv);
        shader.maskTexCoord(1, 0);
        GL11.glVertex2f(16, 0);

        GL11.glEnd();

        shader.end();

        GL11.glDisable(GL11.GL_BLEND);
    }
}

From source file:colonialdisplay.AntDisplayGL.java

private void drawTile(Rectangle bounds, Rectangle2D.Float r) {
    GL11.glBegin(GL11.GL_QUADS);/*from w w  w. ja  v a 2 s.c  o m*/

    GL11.glTexCoord2f(r.x, r.y + r.height);
    GL11.glVertex2f(bounds.x, bounds.y + bounds.height);

    GL11.glTexCoord2f(r.x + r.width, r.y + r.height);
    GL11.glVertex2f(bounds.x + bounds.width, bounds.y + bounds.height);

    GL11.glTexCoord2f(r.x + r.width, r.y);
    GL11.glVertex2f(bounds.x + bounds.width, bounds.y);

    GL11.glTexCoord2f(r.x, r.y);
    GL11.glVertex2f(bounds.x, bounds.y);

    GL11.glEnd();
}

From source file:com.ardor3d.renderer.lwjgl.LwjglFont.java

License:Open Source License

/**
 * <code>buildDisplayList</code> sets up the 256 display lists that are used to render each font character. Each
 * list quad is 16x16, as defined by the font image size.
 *//*from  w w  w.j a  v a 2 s .c om*/
public void buildDisplayList() {
    float cx;
    float cy;

    base = GL11.glGenLists(256);

    for (int loop = 0; loop < 256; loop++) {
        cx = (loop % 16) / 16.0f;
        cy = (loop / 16) / 16.0f;

        GL11.glNewList(base + loop, GL11.GL_COMPILE);
        GL11.glBegin(GL11.GL_QUADS);
        GL11.glTexCoord2f(cx, 1 - cy - 0.0625f);
        GL11.glVertex2i(0, 0);
        GL11.glTexCoord2f(cx + 0.0625f, 1 - cy - 0.0625f);
        GL11.glVertex2i(16, 0);
        GL11.glTexCoord2f(cx + 0.0625f, 1 - cy);
        GL11.glVertex2i(16, 16);
        GL11.glTexCoord2f(cx, 1 - cy);
        GL11.glVertex2i(0, 16);
        GL11.glEnd();
        GL11.glTranslatef(10, 0, 0);
        GL11.glEndList();
    }
}

From source file:com.badlogic.gdx.tools.hiero.unicodefont.UnicodeFont.java

License:Apache License

/** Identical to {@link #drawString(float, float, String, Color, int, int)} but returns a DisplayList which provides access to
 * the width and height of the text drawn. */
public void drawDisplayList(float x, float y, String text, Color color, int startIndex, int endIndex) {
    if (text == null)
        throw new IllegalArgumentException("text cannot be null.");
    if (text.length() == 0)
        return;//from   w w w.  j  av  a  2  s . c  o m
    if (color == null)
        throw new IllegalArgumentException("color cannot be null.");

    x -= paddingLeft;
    y -= paddingTop;

    String displayListKey = text.substring(startIndex, endIndex);

    GL11.glColor4f(color.r, color.g, color.b, color.a);

    GL11.glTranslatef(x, y, 0);

    char[] chars = text.substring(0, endIndex).toCharArray();
    GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length,
            Font.LAYOUT_LEFT_TO_RIGHT);

    int maxWidth = 0, totalHeight = 0, lines = 0;
    int extraX = 0, extraY = ascent;
    boolean startNewLine = false;
    Texture lastBind = null;
    int offsetX = 0;
    for (int glyphIndex = 0, n = vector.getNumGlyphs(); glyphIndex < n; glyphIndex++) {
        int charIndex = vector.getGlyphCharIndex(glyphIndex);
        if (charIndex < startIndex)
            continue;
        if (charIndex > endIndex)
            break;

        int codePoint = text.codePointAt(charIndex);

        Rectangle bounds = getGlyphBounds(vector, glyphIndex, codePoint);
        bounds.x += offsetX;
        Glyph glyph = getGlyph(vector.getGlyphCode(glyphIndex), codePoint, bounds, vector, glyphIndex);

        if (startNewLine && codePoint != '\n') {
            extraX = -bounds.x;
            startNewLine = false;
        }

        if (glyph.getTexture() == null && missingGlyph != null && glyph.isMissing())
            glyph = missingGlyph;
        if (glyph.getTexture() != null) {
            // Draw glyph, only binding a new glyph page texture when necessary.
            Texture texture = glyph.getTexture();
            if (lastBind != null && lastBind != texture) {
                GL11.glEnd();
                lastBind = null;
            }
            if (lastBind == null) {
                texture.bind();
                GL11.glBegin(GL11.GL_QUADS);
                lastBind = texture;
            }
            int glyphX = bounds.x + extraX;
            int glyphY = bounds.y + extraY;
            GL11.glTexCoord2f(glyph.getU(), glyph.getV());
            GL11.glVertex3f(glyphX, glyphY, 0);
            GL11.glTexCoord2f(glyph.getU(), glyph.getV2());
            GL11.glVertex3f(glyphX, glyphY + glyph.getHeight(), 0);
            GL11.glTexCoord2f(glyph.getU2(), glyph.getV2());
            GL11.glVertex3f(glyphX + glyph.getWidth(), glyphY + glyph.getHeight(), 0);
            GL11.glTexCoord2f(glyph.getU2(), glyph.getV());
            GL11.glVertex3f(glyphX + glyph.getWidth(), glyphY, 0);
        }

        if (glyphIndex > 0)
            extraX += paddingRight + paddingLeft + paddingAdvanceX;
        maxWidth = Math.max(maxWidth, bounds.x + extraX + bounds.width);
        totalHeight = Math.max(totalHeight, ascent + bounds.y + bounds.height);

        if (codePoint == '\n') {
            startNewLine = true; // Mac gives -1 for bounds.x of '\n', so use the bounds.x of the next glyph.
            extraY += getLineHeight();
            lines++;
            totalHeight = 0;
        } else if (nativeRendering)
            offsetX += bounds.width;
    }
    if (lastBind != null)
        GL11.glEnd();

    GL11.glTranslatef(-x, -y, 0);
}

From source file:com.damagedearth.Utilities.Components.TrueTypeFont.java

License:Open Source License

private void drawQuad(float drawX, float drawY, float drawX2, float drawY2, float srcX, float srcY, float srcX2,
        float srcY2) {
    float DrawWidth = drawX2 - drawX;
    float DrawHeight = drawY2 - drawY;
    float TextureSrcX = srcX / textureWidth;
    float TextureSrcY = srcY / textureHeight;
    float SrcWidth = srcX2 - srcX;
    float SrcHeight = srcY2 - srcY;
    float RenderWidth = (SrcWidth / textureWidth);
    float RenderHeight = (SrcHeight / textureHeight);

    GL11.glTexCoord2f(TextureSrcX, TextureSrcY);
    GL11.glVertex2f(drawX, drawY);/*from   w  w  w.j a  va2  s  .  co m*/
    GL11.glTexCoord2f(TextureSrcX, TextureSrcY + RenderHeight);
    GL11.glVertex2f(drawX, drawY + DrawHeight);
    GL11.glTexCoord2f(TextureSrcX + RenderWidth, TextureSrcY + RenderHeight);
    GL11.glVertex2f(drawX + DrawWidth, drawY + DrawHeight);
    GL11.glTexCoord2f(TextureSrcX + RenderWidth, TextureSrcY);
    GL11.glVertex2f(drawX + DrawWidth, drawY);
}

From source file:com.dbi.games.fortress.engine.graphics.Sprite.java

public void draw(int x, int y) {
    if (tex == null)
        return;//ww w.ja v a  2s . c om
    GL11.glPushMatrix();

    tex.bind();
    GL11.glTranslatef(x, y, 0);

    GL11.glBegin(GL11.GL_QUADS);
    {
        GL11.glTexCoord2f(0, 0);
        GL11.glVertex2f(0, 0);

        GL11.glTexCoord2f(0, 1f);
        GL11.glVertex2f(0, getHeight());

        GL11.glTexCoord2f(1f, 1f);
        GL11.glVertex2f(getWidth(), getHeight());

        GL11.glTexCoord2f(1f, 0);
        GL11.glVertex2f(getWidth(), 0);

    }
    GL11.glEnd();

    GL11.glPopMatrix();
}

From source file:com.github.begla.blockmania.blocks.Block.java

License:Apache License

/**
 * Generates the display list used for rendering the block.
 *
 * @return The id of the display list//w ww.  j a v  a  2s  .c o m
 */
private int generateDisplayList() {
    int id = glGenLists(1);

    glNewList(id, GL11.GL_COMPILE);
    glBegin(GL_QUADS);
    GL11.glColor3f(1.0f, 1.0f, 1.0f);

    // TOP
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.TOP).x, calcTextureOffsetFor(SIDE.TOP).y);
    GL11.glVertex3f(-0.5f, 0.5f, 0.5f);
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.TOP).x + 0.0624f, calcTextureOffsetFor(SIDE.TOP).y);
    GL11.glVertex3f(0.5f, 0.5f, 0.5f);
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.TOP).x + 0.0624f, calcTextureOffsetFor(SIDE.TOP).y + 0.0624f);
    GL11.glVertex3f(0.5f, 0.5f, -0.5f);
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.TOP).x, calcTextureOffsetFor(SIDE.TOP).y + 0.0624f);
    GL11.glVertex3f(-0.5f, 0.5f, -0.5f);

    // LEFT
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.LEFT).x, calcTextureOffsetFor(SIDE.LEFT).y + 0.0624f);
    GL11.glVertex3f(-0.5f, -0.5f, -0.5f);
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.LEFT).x + 0.0624f, calcTextureOffsetFor(SIDE.LEFT).y + 0.0624f);
    GL11.glVertex3f(-0.5f, -0.5f, 0.5f);
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.LEFT).x + 0.0624f, calcTextureOffsetFor(SIDE.LEFT).y);
    GL11.glVertex3f(-0.5f, 0.5f, 0.5f);
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.LEFT).x, calcTextureOffsetFor(SIDE.LEFT).y);
    GL11.glVertex3f(-0.5f, 0.5f, -0.5f);

    // BACK
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.BACK).x, calcTextureOffsetFor(SIDE.BACK).y + 0.0624f);
    GL11.glVertex3f(-0.5f, -0.5f, 0.5f);
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.BACK).x + 0.0624f, calcTextureOffsetFor(SIDE.BACK).y + 0.0624f);
    GL11.glVertex3f(0.5f, -0.5f, 0.5f);
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.BACK).x + 0.0624f, calcTextureOffsetFor(SIDE.BACK).y);
    GL11.glVertex3f(0.5f, 0.5f, 0.5f);
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.BACK).x, calcTextureOffsetFor(SIDE.BACK).y);
    GL11.glVertex3f(-0.5f, 0.5f, 0.5f);

    // RIGHT
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.RIGHT).x, calcTextureOffsetFor(SIDE.RIGHT).y);
    GL11.glVertex3f(0.5f, 0.5f, -0.5f);
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.RIGHT).x + 0.0624f, calcTextureOffsetFor(SIDE.RIGHT).y);
    GL11.glVertex3f(0.5f, 0.5f, 0.5f);
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.RIGHT).x + 0.0624f,
            calcTextureOffsetFor(SIDE.RIGHT).y + 0.0624f);
    GL11.glVertex3f(0.5f, -0.5f, 0.5f);
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.RIGHT).x, calcTextureOffsetFor(SIDE.RIGHT).y + 0.0624f);
    GL11.glVertex3f(0.5f, -0.5f, -0.5f);

    GL11.glColor3f(0.5f, 0.5f, 0.5f);

    // FRONT
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.FRONT).x, calcTextureOffsetFor(SIDE.FRONT).y);
    GL11.glVertex3f(-0.5f, 0.5f, -0.5f);
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.FRONT).x + 0.0624f, calcTextureOffsetFor(SIDE.FRONT).y);
    GL11.glVertex3f(0.5f, 0.5f, -0.5f);
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.FRONT).x + 0.0624f,
            calcTextureOffsetFor(SIDE.FRONT).y + 0.0624f);
    GL11.glVertex3f(0.5f, -0.5f, -0.5f);
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.FRONT).x, calcTextureOffsetFor(SIDE.FRONT).y + 0.0624f);
    GL11.glVertex3f(-0.5f, -0.5f, -0.5f);
    // BOTTOM
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.BOTTOM).x, calcTextureOffsetFor(SIDE.BOTTOM).y);
    GL11.glVertex3f(-0.5f, -0.5f, -0.5f);
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.BOTTOM).x + 0.0624f, calcTextureOffsetFor(SIDE.BOTTOM).y);
    GL11.glVertex3f(0.5f, -0.5f, -0.5f);
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.BOTTOM).x + 0.0624f,
            calcTextureOffsetFor(SIDE.BOTTOM).y + 0.0624f);
    GL11.glVertex3f(0.5f, -0.5f, 0.5f);
    GL11.glTexCoord2f(calcTextureOffsetFor(SIDE.BOTTOM).x, calcTextureOffsetFor(SIDE.BOTTOM).y + 0.0624f);
    GL11.glVertex3f(-0.5f, -0.5f, 0.5f);

    GL11.glEnd();
    glEndList();

    return id;
}