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:net.roryclaasen.rorysmod.gui.GuiRifleTable.java

License:Apache License

@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) {
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    this.mc.renderEngine.bindTexture(empty);
    if (tileEntity.hasLaser())
        this.mc.renderEngine.bindTexture(table);
    int x = (width - xSize) / 2;
    int y = (height - ySize) / 2;
    this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize);

    if (Settings.showColorBox && slidersEnabled()) {
        int id = ColorUtils.loadTextureFromColour(getColorFromSlider(), 64, 64);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);
        this.drawTexturedModalRect(colorB.xPosition + ((colorB.width - 32) / 2),
                colorB.yPosition + colorB.height + 10, 0, 0, 32, 32);
    }/*from w  w  w  . j  ava  2s  .c  o  m*/
}

From source file:net.roryclaasen.rorysmod.render.RenderLaser.java

License:Apache License

@Override
public void doRender(Entity entity, double x, double y, double z, float yaw, float partialTick) {
    GL11.glPushMatrix();/*from   w  w w .  j a v a 2s.c om*/
    GL11.glTranslated(x, y, z);
    GL11.glRotatef(entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTick - 90.0F,
            0.0F, 1.0F, 0.0F);
    GL11.glRotatef(entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTick,
            0.0F, 0.0F, 1.0F);
    bindTexture(backup);
    if (entity instanceof EntityLaser) {
        EntityLaser laser = (EntityLaser) entity;
        if (Settings.coloredLaser) {
            if (laser.getNBT() != null) {
                if (laser.getLaserData().getItemCount(NBTLaser.Items.Lens) > 0) {
                    int color = ColorUtils.getIntFromColor(Color.RED);
                    if (laser.getNBT().hasKey("color")) {
                        color = ColorUtils.getIntColorFromIntArray(laser.getNBT().getIntArray("color"));
                    }
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, getTexture(color));
                }
            }
        }
    }
    model.render(entity, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
    GL11.glPopMatrix();
}

From source file:net.smert.frameworkgl.opengl.helpers.TextureHelper.java

License:Apache License

public void bind(int textureID) {
    GL11.glBindTexture(textureTarget, textureID);
}

From source file:net.smert.frameworkgl.opengl.helpers.TextureHelper.java

License:Apache License

public void unbind() {
    GL11.glBindTexture(textureTarget, 0);
}

From source file:nintendofan9797.core.textureengine.codechicken.render.TextureUtils.java

public static void prepareTexture(int target, int texture, int min_mag_filter, int wrap) {
    GL11.glBindTexture(target, texture);
    engine().resetBoundTexture();//  w w  w. j a  v a  2 s.c om
    GL11.glTexParameteri(target, GL11.GL_TEXTURE_MIN_FILTER, min_mag_filter);
    GL11.glTexParameteri(target, GL11.GL_TEXTURE_MAG_FILTER, min_mag_filter);
    switch (target) {
    case GL12.GL_TEXTURE_3D:
        GL11.glTexParameteri(target, GL12.GL_TEXTURE_WRAP_R, wrap);
    case GL11.GL_TEXTURE_2D:
        GL11.glTexParameteri(target, GL11.GL_TEXTURE_WRAP_T, wrap);
    case GL11.GL_TEXTURE_1D:
        GL11.glTexParameteri(target, GL11.GL_TEXTURE_WRAP_S, wrap);
    }
}

From source file:okkapel.kkplglutil.util.TextureLoader.java

License:Open Source License

public static Texture loadTexture(File imgFile, boolean pixelated) // Needs rewriting
{
    String fullFilePath = null;/*from  w  w  w  . j a v a2  s . co  m*/
    try {
        fullFilePath = imgFile.getAbsolutePath();

        // The image
        BufferedImage image = ImageIO.read(imgFile);

        // The image pixel data
        int[] pixels = new int[image.getWidth() * image.getHeight() * 4];

        // Write the pixel data into the array
        image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());

        // Create a byte buffer for pixel data
        ByteBuffer pixelBuffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * 4);

        // Put pixel data into the buffer
        for (int y = 0; y < image.getHeight(); y++) {
            for (int x = 0; x < image.getWidth(); x++) {
                // Get the pixel from the array
                int pixel = pixels[y * image.getWidth() + x];

                // Red
                pixelBuffer.put((byte) ((pixel >> 16) & 255));

                // Green
                pixelBuffer.put((byte) ((pixel >> 8) & 255));

                // Blue
                pixelBuffer.put((byte) ((pixel) & 255));

                // Alpha
                pixelBuffer.put((byte) ((pixel >> 24) & 255));
            }
        }

        pixelBuffer.flip();

        int id = GL11.glGenTextures();

        Texture ret = new Texture(id, image.getWidth(), image.getHeight());

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);

        //            Engine.out.debug(id);

        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, image.getWidth(), image.getHeight(), 0,
                GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, pixelBuffer);

        if (pixelated) {
            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);
        } 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_LINEAR);
        }

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);

        return ret;
    } catch (IOException e) {
        e.printStackTrace();
        System.err.println("Failed to load texture from file: " + fullFilePath);
    }

    return null; // TODO: return missing texture
}

From source file:opengl.test.object.CaroTable.java

@Override
protected void initVertex() {
    GL30.glBindVertexArray(vao);//bind vao  

    // position        color       texCoord

    float[] data = new float[] { -0.5f, -0.5f, 0f, 1f, 1f, 1f, 0f, 0f, 0.5f, -0.5f, 0f, 1f, 1f, 1f, 1f, 0f,
            -0.5f, 0.5f, 0f, 1f, 1f, 1f, 0f, 1f, 0.5f, 0.5f, 0f, 1f, 1f, 1f, 1f, 1f };

    dataBuffer = BufferUtils.createFloatBuffer(data.length);
    dataBuffer.put(data);//from w  w w.j  a v  a2 s  . c o  m
    dataBuffer.flip();
    Logger.getGlobal().log(Level.SEVERE, "FloatBuffer capacity  : " + dataBuffer.capacity());

    this.vbo = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, dataBuffer, GL15.GL_STATIC_DRAW);

    this.VertexAttribPointer();

    int[] indices = { 0, 1, 2, 2, 1, 3 };
    IntBuffer indicesBuffer = BufferUtils.createIntBuffer(indices.length);
    indicesBuffer.put(indices);
    indicesBuffer.flip();
    this.ebo = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ebo);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_DYNAMIC_DRAW);

    IntBuffer w = BufferUtils.createIntBuffer(1);
    IntBuffer h = BufferUtils.createIntBuffer(1);
    IntBuffer comp = BufferUtils.createIntBuffer(1);
    STBImage.stbi_set_flip_vertically_on_load(1);
    ByteBuffer image = STBImage.stbi_load("resource/3x3grid.png", w, h, comp, 0);

    int weight = w.get(0);
    int height = h.get(0);
    int compe = comp.get(0);

    Logger.getGlobal().log(Level.FINEST,
            "STBImage load status : " + weight + " " + height + " " + compe + " " + image);

    textureID = GL11.glGenTextures();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);

    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, weight, height, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, image);

    GL30.glBindVertexArray(0);//unbind vao
}

From source file:opengl.test.object.CaroTable.java

@Override
public void render() {

    this.bind();// use porgrma --> ket thuc disable program

    GL30.glBindVertexArray(this.vao);// bind vao -- > unbind vao
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo);
    this.VertexAttribPointer();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ebo);

    GL20.glEnableVertexAttribArray(0);// set index ve 0 

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);

    GL11.glDrawElements(GL11.GL_TRIANGLES, 6, GL11.GL_UNSIGNED_INT, 0);

    GL20.glDisableVertexAttribArray(0);// disable 

    GL30.glBindVertexArray(0);// unbind vao

    this.unbind();// dsiable program
}

From source file:opengl.test.object.cube.wall.java

/**
 * Must be override//from  w  w  w. j a  v  a2s  .co  m
 */
@Override
protected void initVertex() {

    GL30.glBindVertexArray(vao);//bind

    IntBuffer w = BufferUtils.createIntBuffer(1);
    IntBuffer h = BufferUtils.createIntBuffer(1);
    IntBuffer comp = BufferUtils.createIntBuffer(1);
    STBImage.stbi_set_flip_vertically_on_load(1);
    ByteBuffer image = STBImage.stbi_load(this.path, w, h, comp, 0);

    int weight = w.get(0);
    int height = h.get(0);
    int compe = comp.get(0);
    //System.out.println(weight+":"+height+":"+this.path);
    float[] data = new float[] { -x, -y, 0f, 1f, 1f, 1f, 0f, 0f, x, -y, 0f, 1f, 1f, 1f,
            (2 * x) * (this.repeatCount), 0f, -x, y, 0f, 1f, 1f, 1f, 0f, (2 * y) * (this.repeatCount), x, y, 0f,
            1f, 1f, 1f, (2 * x) * (this.repeatCount), (2 * y) * (this.repeatCount), };
    dataBuffer = BufferUtils.createFloatBuffer(data.length);
    dataBuffer.put(data);
    dataBuffer.flip();
    Logger.getGlobal().log(Level.SEVERE, "FloatBuffer capacity  : " + dataBuffer.capacity());

    this.vbo = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, dataBuffer, GL15.GL_STATIC_DRAW);

    this.VertexAttribPointer();

    int[] indices = { 0, 1, 2, 2, 1, 3, };
    IntBuffer indicesBuffer = BufferUtils.createIntBuffer(indices.length);
    indicesBuffer.put(indices);
    indicesBuffer.flip();
    this.ebo = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ebo);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_DYNAMIC_DRAW);

    textureID = GL11.glGenTextures();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);

    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);

    GL11.glTexParameteri(textureID, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
    GL11.glTexParameteri(textureID, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);

    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, weight, height, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, image);

    GL30.glBindVertexArray(0);//unbind
}

From source file:opengl.test.object.cube.wall.java

@Override
public void render() {
    this.bind();// use porgrma --> ket thuc disable program

    GL30.glBindVertexArray(this.vao);// bind vao -- > unbind vao
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, this.vbo);
    this.VertexAttribPointer();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ebo);

    GL20.glEnableVertexAttribArray(0);// set index ve 0 

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);

    GL11.glDrawElements(GL11.GL_TRIANGLE_STRIP, 6, GL11.GL_UNSIGNED_INT, 0);

    GL20.glDisableVertexAttribArray(0);// disable 

    GL30.glBindVertexArray(0);// unbind vao

    this.unbind();// dsiable program
}