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:vengine.VGraphics.java

public void drawString(String s, int x, int y) {
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
    ttf.drawString(x, y, s, new org.newdawn.slick.Color(((float) c.getRed() / 255.0f),
            ((float) c.getGreen() / 255.0f), ((float) c.getBlue() / 255.0f), ((float) c.getAlpha() / 255.0f)));
    if (texture != null) {
        String format[] = texture.split("\\.");
        VResourceManager.bind(texture, format[format.length - 1].toUpperCase());
    }/*w ww  . j av a  2 s.  c  o  m*/
}

From source file:vengine.VGraphics.java

public void drawString(String s, int x, int y, int w) {
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
    int ww = w / 2 - ttf.getWidth(s) / 2;
    ttf.drawString(x + ww, y, s, new org.newdawn.slick.Color(((float) c.getRed() / 255.0f),
            ((float) c.getGreen() / 255.0f), ((float) c.getBlue() / 255.0f), ((float) c.getAlpha() / 255.0f)));
    if (texture != null) {
        String format[] = texture.split("\\.");
        VResourceManager.bind(texture, format[format.length - 1].toUpperCase());
    }/*from   w w  w.  j a  v a 2s . c om*/
}

From source file:voxicity.ChunkNode.java

License:Open Source License

public void render(Frustum camera) {
    if (empty)//from  w ww.  j a va 2  s. co  m
        return;

    AABB chunk_box = new AABB(Constants.Chunk.side_length, Constants.Chunk.side_length,
            Constants.Chunk.side_length);

    chunk_box.center_on(chunk.get_x() + chunk_box.dimensions().x, chunk.get_y() + chunk_box.dimensions().y,
            chunk.get_z() + chunk_box.dimensions().z);

    if (!camera.collides(chunk_box))
        return;

    Renderer.draw_calls++;

    if (shader_prog != 0)
        GL20.glUseProgram(shader_prog);

    // Bind VBO to vertex pointer
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vert_buf);
    GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0);

    // Bind the texture coord VBO to texture pointer
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, tex_buf);
    GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);

    int tex_bak = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);

    for (Batch batch : batches) {
        // Bind the texture for this batch
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, batch.tex);

        // Bind index array
        GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, batch.indices);

        // Draw the block
        GL12.glDrawRangeElements(GL11.GL_QUADS, 0, Constants.Chunk.block_number * 24 - 1, batch.num_elements,
                GL11.GL_UNSIGNED_INT, 0);

        Renderer.batch_draw_calls++;
        Renderer.quads += batch.num_elements;
    }

    // Unbind the texture
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex_bak);

    // Unbind all buffers
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    // Disable the shader once more
    if (shader_prog != 0)
        GL20.glUseProgram(0);
}

From source file:voxicity.Renderer.java

License:Open Source License

private void render_batch(ChunkNode.Batch batch) {
    if (!camera.collides(batch.box))
        return;/*from  www.ja  va  2  s  .  c  o m*/

    Renderer.draw_calls++;

    // Use the shader the batch needs
    GL20.glUseProgram(batch.shader);

    // Bind VBO to vertex pointer
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, batch.vert_buf);
    GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0);

    // Bind the texture coord VBO to texture pointer
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, batch.tex_buf);
    GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);

    // Bind the texture for this batch
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, batch.tex);

    // Bind index array
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, batch.indices);

    // Draw the block
    GL12.glDrawRangeElements(GL11.GL_QUADS, 0, Constants.Chunk.block_number * 24 - 1, batch.num_elements,
            GL11.GL_UNSIGNED_INT, 0);

    Renderer.batch_draw_calls++;
    Renderer.quads += batch.num_elements;

    // Unbind the texture
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);

    // Unbind all buffers
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    GL20.glUseProgram(0);
}

From source file:voxicity.TextureManager.java

License:Open Source License

public static int get_texture(String name) {
    if (name == null)
        return 0;

    if (textures.containsKey(name))
        return textures.get(name).getTextureID();

    try {//from  w ww  . j  a va 2 s.c  o m
        Texture new_tex = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(name), true,
                GL11.GL_NEAREST);
        System.out.println("Loaded texture: " + new_tex);

        textures.put(name, new_tex);

        int tex_bak = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, new_tex.getTextureID());
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex_bak);

        return new_tex.getTextureID();
    } catch (java.io.IOException e) {
        System.out.println("Failed to load texture " + name);
        e.printStackTrace();
        System.exit(0);
    }

    return 0;
}

From source file:wirelessredstone.client.presentation.gui.GuiButtonWirelessExit.java

License:Open Source License

/**
 * Renders the button to the screen.<br>
 * Uses gui/wifi_exit.png/* w ww  .  ja va2  s. co m*/
 * 
 * @param minecraft
 *            minecraft instance
 * @param i
 *            mouse X coordinate
 * @param j
 *            mouse Y coordinate
 */
@Override
public void drawButton(Minecraft minecraft, int i, int j) {
    FontRenderer fontrenderer = minecraft.fontRenderer;

    GL11.glBindTexture(3553 /* GL_TEXTURE_2D */,
            minecraft.renderEngine.getTexture(this.getButtonTexture(false)));
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    boolean flag = i >= xPosition && j >= yPosition && i < xPosition + width && j < yPosition + height;
    int k = getHoverState(flag);
    drawTexturedModalRect(xPosition, yPosition, 0, ((k - 1) * 13), 13, 13);
    drawTexturedModalRect(xPosition + width / 2, yPosition, 200 - width / 2, ((k - 1) * 13), width / 2, height);
    mouseDragged(minecraft, i, j);
}

From source file:wrapper.vbo.Vbo.java

License:Open Source License

public void render() {
    if (vertid != -1) {

        shader.bind();//w  ww  .ja  va 2 s . c  o  m
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, texid);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertid);
        GL20.glEnableVertexAttribArray(vertexattrib);
        GL20.glEnableVertexAttribArray(textureattrib);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertid);
        GL20.glVertexAttribPointer(vertexattrib, 3, GL11.GL_FLOAT, false, 0, 0);
        GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, texcoordid);
        GL20.glVertexAttribPointer(textureattrib, 2, GL11.GL_FLOAT, false, 0, 0);
        GL20.glUniform3f(rotationuniform, rotation_x, rotation_y, rotation_z);
        GL20.glUniform3f(transformuniform, transformation.x, transformation.y, transformation.z);
        GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, vertcount);

        GL20.glDisableVertexAttribArray(vertexattrib);
        GL20.glDisableVertexAttribArray(textureattrib);

        GL11.glEnable(GL11.GL_BLEND);
        shader.unbind();
    } else {

        System.out.println("Error no bound vertid");
        return;
    }

}

From source file:wrath.client.ClientUtils.java

License:Open Source License

/**
 * Loads a LWJGL Texture from an image./*from   w  ww . j a  v  a2 s. c  om*/
 * @param image The {@link java.awt.image.BufferedImage} version of the Texture.
 * @return Returns the LWJGL texture id.
 */
public static int getTexture(BufferedImage image) {
    if (image == null)
        return 0;

    int[] pixels = new int[image.getWidth() * image.getHeight()];
    image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());

    ByteBuffer buffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * 4);

    for (int y = 0; y < image.getHeight(); y++) {
        for (int x = 0; x < image.getWidth(); x++) {
            int pixel = pixels[y * image.getWidth() + x];
            buffer.put((byte) ((pixel >> 16) & 0xFF));
            buffer.put((byte) ((pixel >> 8) & 0xFF));
            buffer.put((byte) (pixel & 0xFF));
            buffer.put((byte) ((pixel >> 24) & 0xFF));
        }
    }
    buffer.flip();

    int id = GL11.glGenTextures();
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, buffer);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
    return id;
}

From source file:wrath.client.graphics.Texture.java

License:Open Source License

/**
 * Constructor./* w  ww  .  ja  v  a  2s  .c  o m*/
 * @param textureFile The image {@link java.io.File} to load the texture from.
 */
protected Texture(File textureFile) {
    this.file = textureFile;
    this.texID = ClientUtils.getTexture(ClientUtils.loadImageFromFile(textureFile));
    Game.getCurrentInstance().getLogger()
            .println("Created texture ID '" + texID + "' from file '" + file.getName() + "'!");
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
    if (Game.getCurrentInstance().getConfig().getBoolean("TexureMipmapping", true))
        GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
    if (Game.getCurrentInstance().getConfig().getBoolean("AntiAliasingTexture", true)) {
        if (Game.getCurrentInstance().getConfig().getBoolean("TexureMipmapping", true)) {
            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
        } else {
            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
        }

    }
    Texture.unbindTextures();
    afterConstructor();
}

From source file:wrath.client.graphics.Texture.java

License:Open Source License

/**
 * Sets the OpenGL Texture state to point to this texture.
 * This should not be called by the developer as it is done automatically.
 *///from   www. ja v a2s. co  m
public void bindTexture() {
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID);
}