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

License:Open Source License

public void draw() {
    GL11.glBegin(GL11.GL_QUADS);// w  w w  . ja va2  s.  c  om
    for (int i = 0; i < this.particleCount; i++) {
        if (this.particles[i] != null) {
            GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, this.decParticle.getWidth(),
                    this.decParticle.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, this.bufParticle);
            GL11.glBindTexture(GL11.GL_ADD, GL11.GL_LOAD);
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, 1);
            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
            GL11.glPushMatrix();
            GL11.glTranslated(this.particles[i].x + (Main.getMain().getCanvas().getX() / 2),
                    this.particles[i].y + (Main.getMain().getCanvas().getY() / 2), 0);
            this.particles[i].draw();
            GL11.glPopMatrix();
        }
    }
    GL11.glEnd();
}

From source file:com.samrj.devil.gl.Texture.java

License:Open Source License

final int tempBind() {
    int oldID = GL11.glGetInteger(binding);
    if (oldID != id)
        GL11.glBindTexture(target, id);
    return oldID;
}

From source file:com.samrj.devil.gl.Texture.java

License:Open Source License

final void tempUnbind(int oldID) {
    if (oldID == id)
        return;
    GL11.glBindTexture(target, oldID);
}

From source file:com.samrj.devil.gl.Texture.java

License:Open Source License

/**
 * Binds this OpenGL texture to whichever texture unit is currently active.
 * // www .j a  v a  2s  . c  om
 * @return This texture.
 */
public final T bind() {
    if (deleted)
        throw new IllegalStateException("Cannot bind deleted texture.");
    GL11.glBindTexture(target, id);
    return getThis();
}

From source file:com.samrj.devil.gl.Texture.java

License:Open Source License

/**
 * Unbinds any texture currently bound to the current texture unit. Might
 * not be this texture! Manage your texture state carefully.
 * //from   ww  w  .  j a va  2  s  . c  o  m
 * @return This texture.
 */
public final T unbind() {
    if (isBound())
        GL11.glBindTexture(target, 0);
    return getThis();
}

From source file:com.savoycraft.gui.help.Slide.java

License:Open Source License

/**
 * Draws the slide. Ignores x and y of rectangle. Call prepareToShow()
 * before calling this; otherwise it will be run automatically on the first
 * call to draw(). (dontPrepare removes this behaviour)
 *///from   www. j a v  a 2  s  .  c om
public void draw(Rectangle validArea, boolean dontPrepare) {
    if (image == null) {
        if (dontPrepare) {
            return;
        } else {
            prepareToShow();
        }
    }

    // Still can't load?
    if (image == null) {
        return;
    }

    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0f);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);

    // Get the width and height of the slide's image on the texture
    // Note that the way MC works, U and V in the texture will always max
    // out at 256, not 512, 1024, or whatever size it really is.
    int textureWidth = (int) (getUsedWidth() / (double) getImage().getWidth() * 256d);
    int textureHeight = (int) (getUsedHeight() / (double) getImage().getHeight() * 256d);

    // Decide the width and height to draw the texture at onto the screen
    // First, compare the aspect ratios of the slide's image and the valid
    // area for it
    double imageAspect = (double) textureWidth / (double) textureHeight;
    double areaAspect = (double) validArea.width / (double) validArea.height;
    int drawWidth, drawHeight;
    if (imageAspect > areaAspect) {
        // If texture is wider than area, width = area's width and change
        // the drawn height
        drawWidth = validArea.width;
        drawHeight = (int) ((double) drawWidth / imageAspect);
    } else {
        // Otherwise, texture is taller than area, height = area's height
        // and change the drawn width
        drawHeight = validArea.height;
        drawWidth = (int) ((double) drawHeight * imageAspect);
    }

    // Calculate the x and y coords of each corner (upper left, lower
    // right)
    int x1 = x + (validArea.width / 2) - (drawWidth / 2);
    int y1 = y + (validArea.height / 2) - (drawHeight / 2);
    int x2 = x + (validArea.width / 2) + (drawWidth / 2);
    int y2 = y + (validArea.height / 2) + (drawHeight / 2);

    // Draw
    double uScale = 1f / 256f;
    double vScale = 1f / 256f;
    Tessellator tess = Tessellator.instance;
    tess.startDrawingQuads();
    tess.addVertexWithUV(x1, y2, 0, 0, textureHeight * vScale);
    tess.addVertexWithUV(x2, y2, 0, textureWidth * uScale, textureHeight * vScale);
    tess.addVertexWithUV(x2, y1, 0, textureWidth * uScale, 0);
    tess.addVertexWithUV(x1, y1, 0, 0, vScale);
    tess.draw();
}

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

License:Mozilla Public License

private int bindTexture(Node node, String imageData) {
    int textureId = GL11.glGenTextures();
    byte[] bitmap = Base64.decodeBase64(imageData);
    try {// w  w w.  j  a  v  a 2 s  .c o m
        PNGDecoder decoder = new PNGDecoder(new ByteArrayInputStream(bitmap));
        int width = decoder.getWidth();
        int height = decoder.getHeight();
        ByteBuffer buffer = ByteBuffer.allocateDirect(4 * width * height);
        decoder.decode(buffer, width * 4, Format.RGBA);
        buffer.flip();

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
        GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA,
                GL11.GL_UNSIGNED_BYTE, buffer);
    } catch (IOException e) {
        e.printStackTrace();
    }

    return textureId;
}

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  .ja v  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

/**
 * Binds the given texture./*from ww  w .  j ava  2 s  .  co m*/
 * 
 * @param texture - The texture to bind.
 */
public static void bindTexture(Texture texture) {
    DrawingUtils.boundTexture = texture.getID();
    GL11.glBindTexture(texture.getTarget(), texture.getID());
}

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

License:Apache License

/**
 * Binds a texture by ID.//from ww w .j  a v a 2s .c  om
 * 
 * @param texture - The ID of the texture to bind.
 */
public static void bindTexture(int texture) {
    DrawingUtils.boundTexture = texture;
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
}