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:opengl.test.object.endgame.endgame.java

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

    Object[] dataInput = objLoad.Wavefront(
            endgame.class.getClassLoader().getResourceAsStream("opengl/test/object/endgame/endgame.obj"), 1.0f,
            1.0f, 1.0f);//from   w  w w  .  j a va 2  s .c  om
    super.dataBuffer = (FloatBuffer) dataInput[0];
    this.size = (int) dataInput[1];

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

    this.VertexAttribPointer();

    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/win.png", w, h, comp, 0);

    textureIDWIN = GL11.glGenTextures();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureIDWIN);
    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, w.get(0), h.get(0), 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, image);

    image = STBImage.stbi_load("resource/lose.png", w, h, comp, 0);

    textureIDLOSE = GL11.glGenTextures();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureIDLOSE);
    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, w.get(0), h.get(0), 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, image);

    image = STBImage.stbi_load("resource/draw.png", w, h, comp, 0);

    textureIDDRAW = GL11.glGenTextures();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureIDDRAW);
    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, w.get(0), h.get(0), 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, image);

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

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

public void render(int status) {

    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();

    GL20.glEnableVertexAttribArray(0);// set index ve 0 
    if (status == endgame.win)
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureIDWIN);
    else if (status == endgame.lose)
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureIDLOSE);
    else/*  w w w.j  a  v a 2 s  .com*/
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureIDDRAW);
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, this.size);
    //GL11.glDrawElements(GL11.GL_TRIANGLES, this.indices.capacity(), GL11.GL_UNSIGNED_INT, 0);// capacity --> luon luon chua max
    //GL11.
    GL20.glDisableVertexAttribArray(0);// disable 

    GL30.glBindVertexArray(0);// unbind vao

    this.unbind();// dsiable program
}

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

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

    // position        color       texCoord

    float[] data = new float[] { -x, -y, z, 1f, 1f, 1f, 0f, 0f, x, -y, z, 1f, 1f, 1f, 1f, 0f, -x, y, z, 1f, 1f,
            1f, 0f, 1f, x, y, z, 1f, 1f, 1f, 1f, 1f };

    dataBuffer = BufferUtils.createFloatBuffer(data.length);
    dataBuffer.put(data);/* w w  w .  j  a  v a  2 s.  c  om*/
    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(this.link, 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.image.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);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, this.ebo);
    this.VertexAttribPointer();

    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.table.table.java

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

    Object[] dataInput = objLoad.Wavefront(
            table.class.getClassLoader().getResourceAsStream("opengl/test/object/table/table.obj"), 1.0f, 1.0f,
            1.0f);/*from  ww  w .  j a v a 2  s . c o  m*/
    super.dataBuffer = (FloatBuffer) dataInput[0];
    this.size = (int) dataInput[1];

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

    this.VertexAttribPointer();

    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/wood2.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.table.table.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();

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

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, this.size);
    //GL11.glDrawElements(GL11.GL_TRIANGLES, this.indices.capacity(), GL11.GL_UNSIGNED_INT, 0);// capacity --> luon luon chua max
    //GL11./*from   w ww .j a va 2 s.c  o  m*/
    GL20.glDisableVertexAttribArray(0);// disable 

    GL30.glBindVertexArray(0);// unbind vao

    this.unbind();// dsiable program
}

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

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

    Object[] dataInput = objLoad.Wavefront(
            tivi.class.getClassLoader().getResourceAsStream("opengl/test/object/tivi/tivi.obj"), 1.0f, 1.0f,
            1.0f);//from ww w  .ja  va2s  .c o m
    super.dataBuffer = (FloatBuffer) dataInput[0];
    this.size = (int) dataInput[1];

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

    this.VertexAttribPointer();

    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/success.png", w, h, comp, 0);

    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, w.get(0), h.get(0), 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, image);

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

From source file:opengl.test.object.tivi.tivi.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();

    GL20.glEnableVertexAttribArray(0);// set index ve 0 
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);

    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, this.size);
    //GL11.glDrawElements(GL11.GL_TRIANGLES, this.indices.capacity(), GL11.GL_UNSIGNED_INT, 0);// capacity --> luon luon chua max
    //GL11./*from w w  w .  j ava  2  s  .  co  m*/
    GL20.glDisableVertexAttribArray(0);// disable 

    GL30.glBindVertexArray(0);// unbind vao

    this.unbind();// dsiable program
}

From source file:org.agpu.oc.client.ClientProxy.java

@Override
public int setup2DScreenTextureTarget(int w, int h) {
    //Generate Texture Space
    int texture = GL11.glGenTextures();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);

    //Generate Blank Texture
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, w, h, 0, GL11.GL_RGB, GL11.GL_UNSIGNED_INT,
            (IntBuffer) null);//from  w  w  w  .  j  av a2  s.com

    //Poor filtering. Needed!
    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);

    System.out.println("Generated AGPU output texture");

    return texture;
}

From source file:org.ajgl.graphics.DisplayList.java

License:Open Source License

/**
 * Compiles or and draws a display list with a texture.
 * @param listID - The display list handler
 * @param beginMode - The OpenGL begin mode
 * @param compileMode - The OpenGL compile mode
 * @param textureID - The texture id to be used
 * @param vertexValues - The array of vertices
 * @param textureValues - Array of local texture vertices
 *///  w ww . j a  v a  2 s . co  m
@OpenGLInfo(fwdCompatible = false, openGLVersion = "1.1", status = "Deprecated")
public static void compileTwoPointList(int listID, @BeginMode int beginMode, @CompileMode int compileMode,
        int textureID, float[] vertexValues, float[] textureValues) {
    GL11.glNewList(listID, compileMode);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);
    GL11.glBegin(beginMode);
    for (int i = 0; i < vertexValues.length - 1; i += 2) {
        GL11.glTexCoord2f(textureValues[i], textureValues[i + 1]);
        GL11.glVertex2f(vertexValues[i], vertexValues[i + 1]);
    }
    GL11.glEnd();
    GL11.glEndList();
}