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:me.sunchiro.game.engine.gl.Graphic.java

License:Open Source License

private synchronized void render() {
    GL11.glClearColor(bgColor.x, bgColor.y, bgColor.z, 0);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    GL20.glUseProgram(shader.getPID());//from w w w.j a va2  s.c  o m
    //

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL30.glBindVertexArray(vaoId);

    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texManager.getTexture(tid));
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
    long offset = 0;
    int shift = 0;
    GL11.glAlphaFunc(GL11.GL_GREATER, 0.4f);
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    for (Drawable object : objects) {
        Matrix4f finalMVP = new Matrix4f(mvpMat);
        Matrix4f modelMat = new Matrix4f();
        Matrix4f scaler = new Matrix4f();
        scaler.scale(object.scale * allScale);
        modelMat.translate(object.translation);
        modelMat.rotateXYZ(object.rotation.x, object.rotation.y, object.rotation.z);
        finalMVP.mul(modelMat);
        finalMVP.mul(scaler);
        finalMVP.get(0, matBuff);
        if (object.isChar) {
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, texManager.getTexture(tid_charmap));
        }
        GL20.glUniformMatrix4fv(shader.getMVPLocation(), false, matBuff);
        GL20.glUniform1i(shader.getInverseLocation(), object.inverseAlpha ? 1 : 0);
        if (object.isVisible())
            GL32.glDrawElementsBaseVertex(GL11.GL_TRIANGLES, object.getIndices().length, GL11.GL_UNSIGNED_BYTE,
                    offset, shift);

        offset += object.getIndices().length;
        shift += object.getVertex().length;
        if (object.isChar) {
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, texManager.getTexture(tid));
        }
    }
    render2d(offset, shift);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL20.glDisableVertexAttribArray(0);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(2);
    GL30.glBindVertexArray(0);
    //
    GL20.glUseProgram(0);
    glfwSwapBuffers(window);
    glfwPollEvents();

}

From source file:me.sunchiro.game.engine.gl.Graphic.java

License:Open Source License

private void render2d(long offset, int shift) {
    cam.getOrthoMVP().get(0, matBuff);/*from w w w  .  java2 s .co m*/
    GL20.glUniformMatrix4fv(shader.getMVPLocation(), false, matBuff);

    for (Drawable object : orthoObjects) {
        if (object.isChar) {
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, texManager.getTexture(tid_charmap));
        }
        GL20.glUniform1i(shader.getInverseLocation(), object.inverseAlpha ? 1 : 0);
        if (object.isVisible())
            GL32.glDrawElementsBaseVertex(GL11.GL_TRIANGLES, object.getIndices().length, GL11.GL_UNSIGNED_BYTE,
                    offset, shift);
        offset += object.getIndices().length;
        shift += object.getVertex().length;
    }
    // static utility function
}

From source file:me.thehutch.fusion.engine.render.opengl.gl20.OpenGL20Texture.java

License:Open Source License

@Override
public void bind() {
    ensureCreated("Texture must be created to bind.");
    // Bind the texture to the current texture unit
    GL11.glBindTexture(GL_TEXTURE_2D, id);
}

From source file:me.thehutch.fusion.engine.render.opengl.gl20.OpenGL20Texture.java

License:Open Source License

@Override
public void bind(int unit) {
    ensureCreated("Texture must be created to bind.");
    // Active the texture unit
    if (unit >= 0) {
        GL13.glActiveTexture(GL_TEXTURE0 + unit);
    }//from   w w w  .  j av  a  2  s. c om
    GL11.glBindTexture(GL_TEXTURE_2D, id);
}

From source file:me.thehutch.fusion.engine.render.opengl.gl20.OpenGL20Texture.java

License:Open Source License

@Override
public void unbind() {
    GL11.glBindTexture(GL_TEXTURE_2D, 0);
}

From source file:me.ukl.api.util.TextureUtil.java

License:MIT License

public static int loadTexture(int[] rgb, int width, int height) {
    IntBuffer rgbBuf = BufferUtils.createIntBuffer(rgb.length);
    rgbBuf.put(rgb);//from  www  .  j  av a2 s  .  co m
    rgbBuf.flip();

    int tex = GL11.glGenTextures();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL12.GL_BGRA,
            GL12.GL_UNSIGNED_INT_8_8_8_8_REV, rgbBuf);
    return tex;
}

From source file:me.ukl.api.util.TextureUtil.java

License:MIT License

public static void bind(int tex) {
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex);
}

From source file:model.ModelMD2.java

@Override
public void draw(float frame, float[] vpMatrix, float[] matrix, RenderEngine engine) {
    if (frame < 0 || frame > header.num_frames - 1)
        return;//from   w w w.j  a  va 2  s. com

    //Select current frame and next
    int frame_0 = frame_ids[(int) Math.floor(frame)];

    int frame_1 = frame_ids[(int) Math.min(Math.ceil(frame), header.num_frames - 1)];
    //Upload frame interpolation

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex_id);

    ShaderUtils.useProgram(shader_id);
    {
        //Upload uniform values
        ShaderUtils.setUniformMatrix4(shader_id, "viewprojMatrix", vpMatrix);
        ShaderUtils.setUniformMatrix4(shader_id, "modelMatrix", matrix);
        ShaderUtils.setUniformVar(shader_id, "frame_interpolated", (float) (frame - Math.floor(frame)));
        //ShaderUtils.setUniformVar(shader_id, "cameraDir", engine.camera.yaw, engine.camera.pitch, engine.camera.roll);
        //Bind frames to VAO
        GL30.glBindVertexArray(vao_id);
        {

            GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, frame_0);//Bind frame 0
            {
                GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 32, 0);
                GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 32, 12);
                GL20.glVertexAttribPointer(2, 3, GL11.GL_FLOAT, false, 32, 20);
            }
            GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

            GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, frame_1);//Bind frame 1
            {
                GL20.glVertexAttribPointer(3, 3, GL11.GL_FLOAT, false, 32, 0);
                GL20.glVertexAttribPointer(4, 2, GL11.GL_FLOAT, false, 32, 12);
                GL20.glVertexAttribPointer(5, 3, GL11.GL_FLOAT, false, 32, 20);
            }

            GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

            //Enable attribs and render
            for (int i = 0; i < 6; i++) {
                GL20.glEnableVertexAttribArray(i);
            }
            {
                GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, header.num_tris * 3);
            }
            for (int i = 0; i < 6; i++) {
                GL20.glDisableVertexAttribArray(i);
            }

        }
        GL30.glBindVertexArray(0);
    }
    ShaderUtils.useProgram(0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
}

From source file:mwisbest.openbase.gui.Button.java

License:Open Source License

@Override
public void render() {
    GL11.glPushMatrix();/*from   w ww .j av a2s . c o  m*/
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glDepthMask(false);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    if (Common.currentTextureID != this.texture.getTextureID()) {
        int texID = this.texture.getTextureID();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID);
        Common.currentTextureID = texID;
    }
    GL11.glTranslatef(this.x, this.y, 0);
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(0, 0);
    GL11.glVertex2f(0, 0);
    GL11.glTexCoord2f(0, this.texture.getHeight());
    GL11.glVertex2f(0, this.height);
    GL11.glTexCoord2f(this.texture.getWidth(), this.texture.getHeight());
    GL11.glVertex2f(this.width, this.height);
    GL11.glTexCoord2f(this.texture.getWidth(), 0);
    GL11.glVertex2f(this.width, 0);
    GL11.glEnd();
    GL11.glPopMatrix();
}

From source file:mwisbest.openbase.opengl.TextureImplementation.java

License:Open Source License

@Override
public void bind() {
    if (lastBind != this) {
        lastBind = this;
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glBindTexture(this.target, this.textureID);
    }/*from w w  w.  j  av a 2  s.  c om*/
}