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:com.runescape.client.revised.editor.modelviewer.Model3D.java

License:Open Source License

public void render(final float x, final float y, final float z, final float rx, final float ry, final float rz,
        final float sx, final float sy, final float sz) {
    GL11.glLoadIdentity();/*from   ww  w.  j  a  v  a2s .  co m*/
    GL11.glTranslatef(x, y, z);
    GL11.glRotatef(rx, 1.0F, 0.0F, 0.0F);
    GL11.glRotatef(ry, 0.0F, 1.0F, 0.0F);
    GL11.glRotatef(rz, 0.0F, 0.0F, 1.0F);
    GL11.glScalef(sx, sy, sz);
    final short[] tri_x = this.triangle_viewspace_x;
    final short[] tri_y = this.triangle_viewspace_y;
    final short[] tri_z = this.triangle_viewspace_z;
    // final short[] tex_map_x = this.texture_map_x;
    // final short[] tex_map_y = this.texture_map_y;
    // final short[] tex_map_z = this.texture_map_z;
    final short[] textures = this.textures;
    final int[] vertices_x = this.vertices_x;
    final int[] vertices_y = this.vertices_y;
    final int[] vertices_z = this.vertices_z;
    final short[] colors = this.colors;
    final float model_scale = 4.0F;
    final float texture_scale = 1.0F;
    if (this.pointers != null) {
        //glEnable(GL_DEPTH_TEST);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        //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);
    }
    Texture texture = null;
    for (int triangle = 0; triangle != this.triangle_count; ++triangle) {
        if ((this.alpha != null) && (this.alpha[triangle] == -1)) {
            continue;
        }
        final int point_a = tri_x[triangle];
        final int point_b = tri_y[triangle];
        final int point_c = tri_z[triangle];
        final int color = Model.hsl2rgb[colors[triangle] & 0xffff];
        int triangle_type;
        if (this.face_fill_attributes == null) {
            triangle_type = 0;
        } else {
            triangle_type = this.face_fill_attributes[triangle] & 3;
        }
        if ((textures != null) && (textures[triangle] != -1)) {
            final int id = textures[triangle] & 0xffff;
            if (ModelConstants.ENABLE_MODEL_TEXTURES && ((texture == null) && (id != -1))) {
                texture = TextureCache.get(id);
            }
            if (texture != null) {
                texture.bind();
            }
        }
        final boolean textured = ModelConstants.ENABLE_MODEL_TEXTURES && (texture != null);
        GL11.glBegin(GL11.GL_TRIANGLES);
        GL11.glColor4ub((byte) (color >>> 16), (byte) (color >>> 8), (byte) color,
                (byte) (this.alpha == null ? 0xff : ~this.alpha[triangle]));
        switch (triangle_type) {
        case 0://shaded triangle
        case 1://flat triangle
            if (textured) {
                GL11.glTexCoord2f(0.0F, 0.0F);
            }
            GL11.glVertex3f(vertices_x[point_a] / model_scale, vertices_y[point_a] / model_scale,
                    vertices_z[point_a] / model_scale);
            if (textured) {
                GL11.glTexCoord2f(0.0F, texture_scale / model_scale);
            }
            GL11.glVertex3f(vertices_x[point_b] / model_scale, vertices_y[point_b] / model_scale,
                    vertices_z[point_b] / model_scale);
            if (textured) {
                GL11.glTexCoord2f(texture_scale / model_scale, texture_scale / model_scale);
            }
            GL11.glVertex3f(vertices_x[point_c] / model_scale, vertices_y[point_c] / model_scale,
                    vertices_z[point_c] / model_scale);
            break;
        case 2://textured?
        case 3://textured?
            final int ptr = this.face_fill_attributes[triangle] >> 2;
            final int tex_point_a = this.texture_map_x[ptr];
            final int tex_point_b = this.texture_map_y[ptr];
            final int tex_point_c = this.texture_map_z[ptr];
            GL11.glTexCoord2f(0.0F, 0.0F);
            GL11.glVertex3f(vertices_x[tex_point_a] / model_scale, vertices_y[tex_point_a] / model_scale,
                    vertices_z[tex_point_a] / model_scale);
            GL11.glTexCoord2f(0.0F, texture_scale / model_scale);
            GL11.glVertex3f(vertices_x[tex_point_b] / model_scale, vertices_y[tex_point_b] / model_scale,
                    vertices_z[tex_point_b] / model_scale);
            GL11.glTexCoord2f(texture_scale / model_scale, texture_scale / model_scale);
            GL11.glVertex3f(vertices_x[tex_point_c] / model_scale, vertices_y[tex_point_c] / model_scale,
                    vertices_z[tex_point_c] / model_scale);
            break;
        }
        GL11.glEnd();
    }
    if (texture != null) {
        GL11.glDisable(GL11.GL_TEXTURE_2D);
    }
}

From source file:com.samrj.devil.geo2d.AAB2.java

License:Open Source License

public void glTexVertex() {
    GL11.glTexCoord2f(0f, 0f);
    GL11.glVertex2f(x0, y0);//from w ww  . ja  v a 2s. c  om
    GL11.glTexCoord2f(0f, 1f);
    GL11.glVertex2f(x0, y1);
    GL11.glTexCoord2f(1f, 1f);
    GL11.glVertex2f(x1, y1);
    GL11.glTexCoord2f(1f, 0f);
    GL11.glVertex2f(x1, y0);
}

From source file:com.samrj.devil.ui.Font.java

License:Open Source License

public void draw(String text, Vec2 pos, Vec2 align) {
    pos = new Vec2(pos.x, pos.y - cellHeight);
    align = new Vec2(align.x - 1.0f, -align.y - 1.0f).mult(0.5f);
    align.x *= getWidth(text);/*w  ww  .java 2s  . com*/
    align.y *= -height;
    pos.add(align);

    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();
    GL11.glTranslatef(Math.round(pos.x), Math.round(pos.y), 0.0f);

    float x0 = 0f;
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    tex.bind();
    GL11.glBegin(GL11.GL_QUADS);
    for (int i = 0; i < text.length(); i++) {
        int charbits = text.charAt(i) - 32;
        int fontposx = charbits & 0xF;
        int fontposy = 15 - (charbits >> 4);
        float u0 = fontposx++ / 16f;
        float v0 = fontposy++ / 16f;
        float u1 = fontposx / 16f;
        float v1 = fontposy / 16f;

        float x1 = x0 + cellHeight;

        GL11.glTexCoord2f(u0, v0);
        GL11.glVertex2f(x0, 0f);
        GL11.glTexCoord2f(u0, v1);
        GL11.glVertex2f(x0, cellHeight);
        GL11.glTexCoord2f(u1, v1);
        GL11.glVertex2f(x1, cellHeight);
        GL11.glTexCoord2f(u1, v0);
        GL11.glVertex2f(x1, 0f);

        x0 += getWidth(text.charAt(i));
    }
    GL11.glEnd();
    GL11.glDisable(GL11.GL_TEXTURE_2D);

    GL11.glPopMatrix();
}

From source file:com.sriramramani.droid.inspector.ui.InspectorCanvas.java

License:Mozilla Public License

private void drawImage(Node node, int textureId, boolean isBackground) {
    GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
    loadColor(ColorType.COLOR_WHITE);

    GL11.glEnable(GL11.GL_TEXTURE_2D);/*from   w  w  w.jav a2s .  c o m*/
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(0.0f, 0.0f);
    GL11.glVertex3f(0.0f, 0.0f, 0.0f);
    GL11.glTexCoord2f(1.0f, 0.0f);
    GL11.glVertex3f(node.bounds.width, 0.0f, 0.0f);
    GL11.glTexCoord2f(1.0f, 1.0f);
    GL11.glVertex3f(node.bounds.width, -node.bounds.height, 0.0f);
    GL11.glTexCoord2f(0.0f, 1.0f);
    GL11.glVertex3f(0.0f, -node.bounds.height, 0.0f);
    GL11.glEnd();
    GL11.glDisable(GL11.GL_TEXTURE_2D);
}

From source file:com.telinc1.rpjg.util.DrawingUtils.java

License:Apache License

/**
 * Draws a rectangle at the given coordinates, but
 * assumes the texture for it has already been bound.
 * /*ww  w .ja  v a  2 s  . c  o  m*/
 * @param x - The X coordinate of the rectangle.
 * @param y - The Y coordinate of the rectangle.
 * @param width - The width of the rectangle.
 * @param height - The height of the rectangle.
 */
public static void drawTexturedQuad(int x, int y, int width, int height) {
    DrawingUtils.startDrawing(GL11.GL_QUADS);
    GL11.glTexCoord2f(0, 0);
    GL11.glVertex2i(x, y);

    GL11.glTexCoord2f(1, 0);
    GL11.glVertex2i(x + width, y);

    GL11.glTexCoord2f(1, 1);
    GL11.glVertex2i(x + width, y + height);

    GL11.glTexCoord2f(0, 1);
    GL11.glVertex2i(x, y + height);
    DrawingUtils.stopDrawing();
}

From source file:com.telinc1.rpjg.util.DrawingUtils.java

License:Apache License

/**
 * Draws a textured rectangle, but uses a texture mapper
 * to pull its texture from an atlas.//from  w  w  w . j a  va2 s.c  om
 * 
 * @param mapper - The {@link TextureMapper texture mapper} to use.
 * @param x - The X coordinate of the rectangle.
 * @param y - The Y coordinate of the rectangle.
 * @param width - The width of the rectangle.
 * @param height - The height of the rectangle.
 */
public static void drawMappedQuad(TextureMapper mapper, int x, int y, int width, int height) {
    if (mapper.getTexture().getID() != DrawingUtils.boundTexture) {
        DrawingUtils.bindTexture(mapper.getTexture());
    }

    DrawingUtils.startDrawing(GL11.GL_QUADS);
    GL11.glTexCoord2f(mapper.getU(), mapper.getV());
    GL11.glVertex2i(x, y);

    GL11.glTexCoord2f(mapper.getU2(), mapper.getV());
    GL11.glVertex2i(x + width, y);

    GL11.glTexCoord2f(mapper.getU2(), mapper.getV2());
    GL11.glVertex2i(x + width, y + height);

    GL11.glTexCoord2f(mapper.getU(), mapper.getV2());
    GL11.glVertex2i(x, y + height);
    DrawingUtils.stopDrawing();
}

From source file:com.telinc1.rpjg.util.DrawingUtils.java

License:Apache License

/**
 * Draws a textured rectangle with a texture mapper,
 * but doesn't start of end drawing./* w  w  w.  j a  va 2  s. c o m*/
 * 
 * @param mapper - The {@link TextureMapper texture mapper} to use.
 * @param x - The X coordinate of the rectangle.
 * @param y - The Y coordinate of the rectangle.
 * @param width - The width of the rectangle.
 * @param height - The height of the rectangle.
 */
public static void drawConsecutiveMappedQuad(TextureMapper mapper, int x, int y, int width, int height) {
    GL11.glTexCoord2f(mapper.getU(), mapper.getV());
    GL11.glVertex2i(x, y);

    GL11.glTexCoord2f(mapper.getU2(), mapper.getV());
    GL11.glVertex2i(x + width, y);

    GL11.glTexCoord2f(mapper.getU2(), mapper.getV2());
    GL11.glVertex2i(x + width, y + height);

    GL11.glTexCoord2f(mapper.getU(), mapper.getV2());
    GL11.glVertex2i(x, y + height);
}

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

License:Open Source License

/**
 * Render a rectangle at the given position.
 *
 * @param x Rectangle X position.//from w ww .  j  ava  2 s  .  com
 * @param y Rectangle Y position.
 * @param w Rectangle width.
 * @param h Rectangle height.
 */
public static void renderRectangle(float x, float y, float w, float h) {
    // Enable line drawing mode
    GL11.glBegin(GL11.GL_QUADS);

    // Draw the grid
    GL11.glVertex3f(x, y, 0f);
    GL11.glTexCoord2f(1, 1);
    GL11.glVertex3f(x + w, y, 0f);
    GL11.glTexCoord2f(1, 0);
    GL11.glVertex3f(x + w, y + h, 0f);
    GL11.glTexCoord2f(0, 0);
    GL11.glVertex3f(x, y + h, 0f);
    GL11.glTexCoord2f(0, 1);

    // Finish drawing
    GL11.glEnd();
}

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

License:Open Source License

/**
 * Renders a nonstandard vertical rectangle (nonstandard referring primarily to
 * the texture size (ie: when we're not pulling a single element out of a 16x16
 * grid).  This differs from renderVertical also in that we specify two full
 * (x, y, z) coordinates for the bounds, instead of passing in y and a height.
 * Texture coordinates are passed in as the usual float from 0 to 1.
 *
 * @param tx  X index within the texture
 * @param ty  Y index within the texture
 * @param tdx Width of texture/*from w w  w . j  av a 2s. co  m*/
 * @param tdy Height of texture
 * @param x1
 * @param y1
 * @param z1
 * @param x2
 * @param y2
 * @param z2
 */
public static void renderNonstandardVertical(float tx, float ty, float tdx, float tdy, float x1, float y1,
        float z1, float x2, float y2, float z2) {
    GL11.glBegin(GL11.GL_TRIANGLE_STRIP);

    GL11.glTexCoord2f(tx, ty + tdy);
    GL11.glVertex3f(x1, y1, z1);

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

    GL11.glTexCoord2f(tx, ty);
    GL11.glVertex3f(x1, y2, z1);

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

    // unflipped textures
    /*
    GL11.glTexCoord2f(tx, ty);
    GL11.glVertex3f(x1, y1, z1);
            
    GL11.glTexCoord2f(tx + tdx, ty);
    GL11.glVertex3f(x2, y1, z2);
            
    GL11.glTexCoord2f(tx, ty + tdy);
    GL11.glVertex3f(x1, y2, z1);
            
    GL11.glTexCoord2f(tx + tdx, ty + tdy);
    GL11.glVertex3f(x2, y2, z2);
     */
    GL11.glEnd();
}

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

License:Open Source License

/**
 * Renders a somewhat-arbitrary vertical rectangle.  Pass in (x, z) pairs for the endpoints,
 * and information about the height.  The texture variables given are in terms of 1/16ths of
 * the texture square, which means that for the default Minecraft 16x16 texture, they're in
 * pixels.//from w  w w  .  java  2 s  . c  om
 *
 * @param x1
 * @param z1
 * @param x2
 * @param z2
 * @param y      The lower part of the rectangle
 * @param height Height of the rectangle.
 */
public static void renderVertical(float tx, float ty, float tdx, float tdy, float x1, float z1, float x2,
        float z2, float y, float height) {
    GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
    GL11.glTexCoord2f(tx, ty);
    GL11.glVertex3f(x1, y + height, z1);

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

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

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