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:de.keyle.dungeoncraft.editor.editors.world.render.Renderer.java

License:Open Source License

/**
 * Renders an arbitrary horizontal rectangle (will be orthogonal).  The texture parameters
 * are specified in terms of 1/16ths of the texture (which equates to one pixel, when using
 * the default 16x16 Minecraft texture./* ww  w.  j  a v a 2  s .  c o  m*/
 *
 * @param x1
 * @param z1
 * @param x2
 * @param z2
 * @param y
 */
public static void renderHorizontal(float x1, float z1, float x2, float z2, float y, float tex_start_x,
        float tex_start_y, float tex_width, float tex_height, boolean flip_tex) {
    GL11.glBegin(GL11.GL_TRIANGLE_STRIP);

    if (flip_tex) {
        GL11.glTexCoord2f(tex_start_x, tex_start_y);
        GL11.glVertex3f(x1, y, z2);

        GL11.glTexCoord2f(tex_start_x + tex_width, tex_start_y);
        GL11.glVertex3f(x2, y, z2);

        GL11.glTexCoord2f(tex_start_x, tex_start_y + tex_height);
        GL11.glVertex3f(x1, y, z1);

        GL11.glTexCoord2f(tex_start_x + tex_width, tex_start_y + tex_height);
        GL11.glVertex3f(x2, y, z1);
    } else {
        GL11.glTexCoord2f(tex_start_x, tex_start_y);
        GL11.glVertex3f(x1, y, z1);

        GL11.glTexCoord2f(tex_start_x + tex_width, tex_start_y);
        GL11.glVertex3f(x1, y, z2);

        GL11.glTexCoord2f(tex_start_x, tex_start_y + tex_height);
        GL11.glVertex3f(x2, y, z1);

        GL11.glTexCoord2f(tex_start_x + tex_width, tex_start_y + tex_height);
        GL11.glVertex3f(x2, y, z2);
    }
    GL11.glEnd();
}

From source file:de.keyle.dungeoncraft.editor.editors.world.render.Renderer.java

License:Open Source License

/**
 * Renders a nonstandard horizontal rectangle (nonstandard referring primarily to
 * the texture size (ie: when we're not pulling a single element out of a 16x16
 * grid).//w  w  w .j  a  v a 2  s. com
 *
 * @param tx  X index within the texture
 * @param ty  Y index within the texture
 * @param tdx Width of texture
 * @param tdy Height of texture
 * @param x1
 * @param z1
 * @param x2
 * @param z2
 * @param y
 */
public static void renderNonstandardHorizontal(float tx, float ty, float tdx, float tdy, float x1, float z1,
        float x2, float z2, float y) {
    GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
    GL11.glTexCoord2f(tx, ty);
    GL11.glVertex3f(x1, y, z1);

    GL11.glTexCoord2f(tx + tdx, ty);
    GL11.glVertex3f(x1, y, z2);

    GL11.glTexCoord2f(tx, ty + tdy);
    GL11.glVertex3f(x2, y, z1);

    GL11.glTexCoord2f(tx + tdx, ty + tdy);
    GL11.glVertex3f(x2, y, z2);
    GL11.glEnd();
}

From source file:de.keyle.dungeoncraft.editor.editors.world.render.Renderer.java

License:Open Source License

/**
 * Render a surface on a horizontal plane; pass in all four verticies.  This can result,
 * obviously, in non-rectangular and non-orthogonal shapes.
 *
 * @param tx/*w  ww.  j a  va 2s  .  c o  m*/
 * @param ty
 * @param tdx
 * @param tdy
 * @param x1
 * @param z1
 * @param x2
 * @param z2
 * @param x3
 * @param z3
 * @param x4
 * @param z4
 * @param y
 */
public static void renderHorizontalAskew(float tx, float ty, float tdx, float tdy, float x1, float z1, float x2,
        float z2, float x3, float z3, float x4, float z4, float y) {
    GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
    GL11.glTexCoord2f(tx, ty);
    GL11.glVertex3f(x1, y, z1);

    GL11.glTexCoord2f(tx + tdx, ty);
    GL11.glVertex3f(x2, y, z2);

    GL11.glTexCoord2f(tx, ty + tdy);
    GL11.glVertex3f(x3, y, z3);

    GL11.glTexCoord2f(tx + tdx, ty + tdy);
    GL11.glVertex3f(x4, y, z4);
    GL11.glEnd();
}

From source file:de.keyle.dungeoncraft.editor.editors.world.render.Renderer.java

License:Open Source License

/**
 * Renders a block sized face with the given facing.
 *
 * @param dimensions Texture dimensions/*  w  ww .  j a  va  2 s  . com*/
 * @param x
 * @param y
 * @param z
 * @param facing     The face that should be drawn
 */
public static void renderBlockFace(TextureDimensions dimensions, float x, float y, float z, Facing facing) {
    float curFace[][];
    switch (facing) {
    case UP:
        curFace = new float[][] { { 0f, 1f, 1f }, { 0f, 1f, 0f }, { 1f, 1f, 1f }, { 1f, 1f, 0f } };
        break;
    case DOWN:
        curFace = new float[][] { { 0f, 0f, 1f }, { 0f, 0f, 0f }, { 1f, 0f, 1f }, { 1f, 0f, 0f } };
        break;
    case NORTH:
        curFace = new float[][] { { 0f, 1f, 0f }, { 1f, 1f, 0f }, { 0f, 0f, 0f }, { 1f, 0f, 0f } };
        break;
    case SOUTH:
        curFace = new float[][] { { 0f, 1f, 1f }, { 1f, 1f, 1f }, { 0f, 0f, 1f }, { 1f, 0f, 1f } };
        break;
    case WEST:
        curFace = new float[][] { { 0f, 1f, 1f }, { 0f, 1f, 0f }, { 0f, 0f, 1f }, { 0f, 0f, 0f } };
        break;
    case EAST:
        curFace = new float[][] { { 1f, 1f, 1f }, { 1f, 1f, 0f }, { 1f, 0f, 1f }, { 1f, 0f, 0f } };
        break;
    default:
        return;
    }

    GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
    GL11.glTexCoord2f(dimensions.getTexLeft(), dimensions.getTexTop());
    GL11.glVertex3f(x + curFace[0][0], y + curFace[0][1], z + curFace[0][2]);

    GL11.glTexCoord2f(dimensions.getTexLeft() + dimensions.getTexWidth(), dimensions.getTexTop());
    GL11.glVertex3f(x + curFace[1][0], y + curFace[1][1], z + curFace[1][2]);

    GL11.glTexCoord2f(dimensions.getTexLeft(), dimensions.getTexTop() + dimensions.getTexHeight());
    GL11.glVertex3f(x + curFace[2][0], y + curFace[2][1], z + curFace[2][2]);

    GL11.glTexCoord2f(dimensions.getTexLeft() + dimensions.getTexWidth(),
            dimensions.getTexTop() + dimensions.getTexHeight());
    GL11.glVertex3f(x + curFace[3][0], y + curFace[3][1], z + curFace[3][2]);
    GL11.glEnd();
}

From source file:dripdisplay.DripDisplayLWJGL.java

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

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

    GL11.glTexCoord2f(r.x + r.width, r.y + r.height);
    GL11.glVertex2f(bounds.getX() + bounds.getWidth(), bounds.getY() + bounds.getHeight());

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

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

    GL11.glEnd();
}

From source file:eb.core.gui.GuiHelper.java

License:LGPL

public static void drawTexturedRect(int x, int y, int width, int height, int textureSize, int[] u, int[] v) {
    float uf[] = new float[] { (float) u[0] / (float) textureSize, (float) u[1] / (float) textureSize };
    float vf[] = new float[] { (float) v[0] / (float) textureSize, (float) v[1] / (float) textureSize };

    GL11.glBegin(GL11.GL_QUADS);//from  w w  w  .j av a2 s.  c  o  m
    GL11.glTexCoord2f(uf[0], vf[0]);
    GL11.glVertex2i(x, y);
    GL11.glTexCoord2f(uf[0], vf[1]);
    GL11.glVertex2i(x, y + height);
    GL11.glTexCoord2f(uf[1], vf[1]);
    GL11.glVertex2i(x + width, y + height);
    GL11.glTexCoord2f(uf[1], vf[0]);
    GL11.glVertex2i(x + width, y);
    GL11.glEnd();
}

From source file:edu.csun.ecs.cs.multitouchj.ui.control.FramedControl.java

License:Apache License

public void render() {
    // render with no texture
    Texture texture = getTexture();//  w  ww  . j a  v a 2  s  .co  m
    setTexture((Texture) null);

    GL11.glPushMatrix();
    GL11.glLoadIdentity();
    super.render();
    GL11.glPopMatrix();

    setTexture(texture);

    // rendering texture
    if ((!isVisible()) || (texture == null)) {
        return;
    }

    Size controlSize = getSize();
    Size imageSize = texture.getImage().getSize();
    float margin = getMargin();
    if ((margin >= controlSize.getWidth()) || (margin >= controlSize.getHeight())) {
        margin = 0.0f;
    }

    Color color = getColor();
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glColor4f(((float) color.getRed() / 255.0f), ((float) color.getGreen() / 255.0f),
            ((float) color.getBlue() / 255.0f), getOpacity());

    Point position = getOpenGlPosition();
    float halfWidth = (controlSize.getWidth() / 2.0f);
    float halfHeight = (controlSize.getHeight() / 2.0f);
    GL11.glTranslatef(position.getX(), position.getY(), 0.0f);

    float rotation = OpenGlUtility.getOpenGlRotation(getRotation());
    GL11.glRotatef(rotation, 0.0f, 0.0f, 1.0f);

    // render texture
    GL11.glEnable(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT);
    GL11.glBindTexture(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT, texture.getId().intValue());

    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(0.0f, 0.0f);
    GL11.glVertex3f(((-1 * halfWidth) + margin), ((-1 * halfHeight) + margin), 0.0f);

    GL11.glTexCoord2f(imageSize.getWidth(), 0.0f);
    GL11.glVertex3f((halfWidth - margin), ((-1 * halfHeight) + margin), 0.0f);

    GL11.glTexCoord2f(imageSize.getWidth(), imageSize.getHeight());
    GL11.glVertex3f((halfWidth - margin), (halfHeight - margin), 0.0f);

    GL11.glTexCoord2f(0.0f, imageSize.getHeight());
    GL11.glVertex3f(((-1 * halfWidth) + margin), (halfHeight - margin), 0.0f);
    GL11.glEnd();
}

From source file:edu.csun.ecs.cs.multitouchj.ui.control.TexturedControl.java

License:Apache License

public void render() {
    if (!isVisible()) {
        return;/*  ww  w .  ja  va 2s.  co  m*/
    }

    Size controlSize = getSize();
    Size imageSize = null;
    if (texture != null) {
        imageSize = texture.getImage().getSize();
    }

    Color color = getColor();
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glColor4f(((float) color.getRed() / 255.0f), ((float) color.getGreen() / 255.0f),
            ((float) color.getBlue() / 255.0f), getOpacity());

    Point position = getOpenGlPosition();
    float halfWidth = (controlSize.getWidth() / 2.0f);
    float halfHeight = (controlSize.getHeight() / 2.0f);
    GL11.glTranslatef(position.getX(), position.getY(), 0.0f);

    float rotation = OpenGlUtility.getOpenGlRotation(getRotation());
    GL11.glRotatef(rotation, 0.0f, 0.0f, 1.0f);

    if (texture != null) {
        GL11.glEnable(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT);
        GL11.glBindTexture(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT, texture.getId().intValue());
    } else {
        GL11.glDisable(EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT);
    }

    // bl -> br -> tr -> tl
    GL11.glBegin(GL11.GL_QUADS);
    if (texture != null) {
        GL11.glTexCoord2f(0.0f, 0.0f);
    }
    GL11.glVertex3f((-1 * halfWidth), (-1 * halfHeight), 0.0f);

    if (texture != null) {
        GL11.glTexCoord2f(imageSize.getWidth(), 0.0f);
    }
    GL11.glVertex3f(halfWidth, (-1 * halfHeight), 0.0f);

    if (texture != null) {
        GL11.glTexCoord2f(imageSize.getWidth(), imageSize.getHeight());
    }
    GL11.glVertex3f(halfWidth, halfHeight, 0.0f);

    if (texture != null) {
        GL11.glTexCoord2f(0.0f, imageSize.getHeight());
    }
    GL11.glVertex3f((-1 * halfWidth), halfHeight, 0.0f);
    GL11.glEnd();
}

From source file:engine.obj.OBJLoader.java

License:Open Source License

/**
 * Renders a given <code>Obj</code> file.
 *
 * @param model the <code>Obj</code> file to be rendered
 *//*from ww w .  j ava  2  s.co  m*/
public void render(Obj model) {
    GL11.glMaterialf(GL_FRONT, GL_SHININESS, 120);
    GL11.glBegin(GL_TRIANGLES);
    {
        for (Obj.Face face : model.getFaces()) {
            Vector3f[] normals = { model.getNormals().get(face.getNormals()[0] - 1),
                    model.getNormals().get(face.getNormals()[1] - 1),
                    model.getNormals().get(face.getNormals()[2] - 1) };
            Vector2f[] texCoords = { model.getTextureCoordinates().get(face.getTextureCoords()[0] - 1),
                    model.getTextureCoordinates().get(face.getTextureCoords()[1] - 1),
                    model.getTextureCoordinates().get(face.getTextureCoords()[2] - 1) };
            Vector3f[] vertices = { model.getVertices().get(face.getVertices()[0] - 1),
                    model.getVertices().get(face.getVertices()[1] - 1),
                    model.getVertices().get(face.getVertices()[2] - 1) };
            {
                GL11.glNormal3f(normals[0].getX(), normals[0].getY(), normals[0].getZ());
                GL11.glTexCoord2f(texCoords[0].getX(), texCoords[0].getY());
                GL11.glVertex3f(vertices[0].getX(), vertices[0].getY(), vertices[0].getZ());
                GL11.glNormal3f(normals[1].getX(), normals[1].getY(), normals[1].getZ());
                GL11.glTexCoord2f(texCoords[1].getX(), texCoords[1].getY());
                GL11.glVertex3f(vertices[1].getX(), vertices[1].getY(), vertices[1].getZ());
                GL11.glNormal3f(normals[2].getX(), normals[2].getY(), normals[2].getZ());
                GL11.glTexCoord2f(texCoords[2].getX(), texCoords[2].getY());
                GL11.glVertex3f(vertices[2].getX(), vertices[2].getY(), vertices[2].getZ());
            }
        }
    }
    GL11.glEnd();
}

From source file:eu.over9000.veya.gui.TrueTypeFont.java

License:Open Source License

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

    GL11.glTexCoord2f(TextureSrcX, TextureSrcY);
    GL11.glVertex2f(drawX, drawY);/*from  w  ww  . ja  v  a 2 s . c  o  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);
}