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.grillecube.client.opengl.GLTexture.java

public final void bind(int texture, int target) {
    GL13.glActiveTexture(texture);/*from   w  w  w  .  j a v a2  s.  c o  m*/
    GL11.glBindTexture(target, this.glID);
}

From source file:com.grillecube.client.opengl.GLTexture.java

public final void unbind(int target) {
    GL11.glBindTexture(target, 0);
}

From source file:com.grillecube.engine.opengl.object.GLTexture.java

public void bind(int target) {
    GL11.glBindTexture(target, this._glID);
}

From source file:com.grillecube.engine.opengl.object.GLTexture.java

public void bind(int texture, int target) {
    GL13.glActiveTexture(texture);
    GL11.glBindTexture(target, this._glID);
}

From source file:com.grillecube.engine.opengl.object.GLTexture.java

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

From source file:com.kauridev.lunarfever.graphics.Texture.java

License:Open Source License

public void bind() {
    if (!valid()) {
        throw new IllegalStateException();
    }// w w w  .jav  a 2 s .c o  m

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);
}

From source file:com.kauridev.lunarfever.graphics.TextureLoader.java

License:Open Source License

public static Texture loadTexture(String file) {
    Texture texture = cache.get(file);/*w ww  .j  a v  a 2 s .  c  o  m*/

    if (texture != null && texture.getTexture().valid()) {
        return texture;
    }

    BufferedImage image = loadImage(file);

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    int id = GL11.glGenTextures();

    // bind
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);

    // set filter
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);

    // set wrap
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);

    // set unpack alignment
    GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);

    // send data to gpu
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, loadBuffer(image));

    // Create texture
    texture = new Texture(id, image.getWidth(), image.getHeight());

    cache.put(file, texture);
    return texture;
}

From source file:com.microsoft.Malmo.Utils.TextureHelper.java

License:Open Source License

public static void glBindTexture(int target, int texture) {
    // The Minecraft render code is selecting a texture.
    // If we are producing a colour map, this is our opportunity to activate our special fragment shader,
    // which will ignore the texture and use a solid colour - either the colour we pass in, or a colour based
    // on the texture coords (if using the block texture atlas).
    if (isProducingColourMap && colourmapFrame) {
        if (shaderID != -1) {
            // Have we encountered this texture before?
            Integer col = texturesToColours.get(texture);
            if (col == null) {
                // No - are we drawing an entity?
                if (currentEntity != null) {
                    // Has the user requested a specific mapping?
                    if (idealMobColours != null) {
                        // Yes, in which case use black unless a mapping is found:
                        col = 0;/*from ww  w.j a  v  a  2 s  .  c  om*/
                        String entName = EntityList.getKey(currentEntity).toString();
                        for (String ent : idealMobColours.keySet()) {
                            if (entName.equals(ent)) {
                                col = idealMobColours.get(ent);
                            }
                        }
                    } else {
                        // Provide a default mapping from entity to colour
                        String ent = EntityList.getEntityString(currentEntity);
                        col = (ent.hashCode()) % 0xffffff;
                    }
                    texturesToColours.put(texture, col);
                } else {
                    // Not drawing an entity. Check the misc mappings:
                    for (String resID : miscTexturesToColours.keySet()) {
                        ITextureObject tex = Minecraft.getMinecraft().getTextureManager()
                                .getTexture(new ResourceLocation(resID));
                        if (tex != null && tex.getGlTextureId() == texture) {
                            // Match
                            col = miscTexturesToColours.get(resID);
                        }
                    }
                    if (col == null) {
                        // Still no match.
                        // Finally, see if this is the block atlas texture:
                        ITextureObject blockatlas = Minecraft.getMinecraft().getTextureManager()
                                .getTexture(new ResourceLocation("textures/atlas/blocks.png"));
                        if (blockatlas != null && blockatlas.getGlTextureId() == texture) {
                            col = -1;
                        }
                    }
                    if (col != null) // Put this in the map for easy access next time.
                        texturesToColours.put(texture, col);
                }
            }
            if (col != null) {
                OpenGlHelper.glUseProgram(shaderID);
                int entColUniformLocR = OpenGlHelper.glGetUniformLocation(shaderID, "entityColourR");
                int entColUniformLocG = OpenGlHelper.glGetUniformLocation(shaderID, "entityColourG");
                int entColUniformLocB = OpenGlHelper.glGetUniformLocation(shaderID, "entityColourB");
                if (entColUniformLocR != -1 && entColUniformLocG != -1 && entColUniformLocB != -1) {
                    OpenGlHelper.glUniform1i(entColUniformLocR, col != -1 ? (col >> 16) & 0xff : -1);
                    OpenGlHelper.glUniform1i(entColUniformLocG, col != -1 ? (col >> 8) & 0xff : -1);
                    OpenGlHelper.glUniform1i(entColUniformLocB, col != -1 ? col & 0xff : -1);
                }
            } else
                OpenGlHelper.glUseProgram(0);
        }
    }
    // Finally, pass call on to OpenGL:
    GL11.glBindTexture(target, texture);
}

From source file:com.mtbs3d.minecrift.FBOParams.java

License:LGPL

public FBOParams(String fboName, int textureType, int internalFormat, int baseFormat, int bufferType,
        int fboWidth, int fboHeight) throws Exception {
    Minecraft mc = Minecraft.getMinecraft();
    _textureType = textureType;//  ww  w  . jav  a  2s . com

    if (fboSupport == FBO_SUPPORT.USE_EXT_UNKNOWN) {
        // The framebuffer, which regroups 0, 1, or more textures, and 0 or 1 depth buffer.
        try {
            _frameBufferId = GL30.glGenFramebuffers();
            fboSupport = FBO_SUPPORT.USE_GL30;
        } catch (IllegalStateException ex) {
            System.out.println(
                    "[Minecrift] FBO creation: GL30.glGenFramebuffers not supported. Attempting to use EXTFramebufferObject.glGenFramebuffersEXT");
            fboSupport = FBO_SUPPORT.USE_EXT;

            try {
                _frameBufferId = EXTFramebufferObject.glGenFramebuffersEXT();
            } catch (IllegalStateException ex1) {
                System.out.println(
                        "[Minecrift] FBO creation: EXTFramebufferObject.glGenFramebuffersEXT not supported, FBO creation failed.");
                throw ex1;
            }
        }
    } else if (fboSupport == FBO_SUPPORT.USE_GL30) {
        _frameBufferId = GL30.glGenFramebuffers();
    } else {
        _frameBufferId = EXTFramebufferObject.glGenFramebuffersEXT();
    }

    if (fboSupport == FBO_SUPPORT.USE_GL30) {
        _colorTextureId = GL11.glGenTextures();
        _depthRenderBufferId = GL30.glGenRenderbuffers();

        GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, _frameBufferId);
        checkGLError("FBO bind framebuffer");

        GL11.glBindTexture(textureType, _colorTextureId);
        checkGLError("FBO bind texture");

        GL11.glEnable(textureType);
        GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
        GL11.glTexImage2D(textureType, 0, internalFormat, fboWidth, fboHeight, 0, baseFormat, bufferType,
                (java.nio.ByteBuffer) null);

        System.out.println("[Minecrift] FBO '" + fboName + "': w: " + fboWidth + ", h: " + fboHeight);

        GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, textureType,
                _colorTextureId, 0);

        checkGLError("FBO bind texture framebuffer");

        GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, _depthRenderBufferId); // bind the depth renderbuffer
        GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL14.GL_DEPTH_COMPONENT24, fboWidth, fboHeight); // get the data space for it
        GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER,
                _depthRenderBufferId);
        checkGLError("FBO bind depth framebuffer");
    } else {
        _colorTextureId = GL11.glGenTextures();
        _depthRenderBufferId = EXTFramebufferObject.glGenRenderbuffersEXT();

        EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, _frameBufferId);
        checkGLError("FBO bind framebuffer");

        GL11.glBindTexture(textureType, _colorTextureId);
        checkGLError("FBO bind texture");

        GL11.glEnable(textureType);
        GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameterf(textureType, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
        GL11.glTexImage2D(textureType, 0, internalFormat, fboWidth, fboHeight, 0, baseFormat, bufferType,
                (java.nio.ByteBuffer) null);
        System.out.println("[Minecrift] FBO '" + fboName + "': w: " + fboWidth + ", h: " + fboHeight);

        EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, textureType, _colorTextureId, 0);

        checkGLError("FBO bind texture framebuffer");

        EXTFramebufferObject.glBindRenderbufferEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT,
                _depthRenderBufferId); // bind the depth renderbuffer
        EXTFramebufferObject.glRenderbufferStorageEXT(EXTFramebufferObject.GL_RENDERBUFFER_EXT,
                GL14.GL_DEPTH_COMPONENT24, fboWidth, fboHeight); // get the data space for it
        EXTFramebufferObject.glFramebufferRenderbufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
                EXTFramebufferObject.GL_DEPTH_ATTACHMENT_EXT, EXTFramebufferObject.GL_RENDERBUFFER_EXT,
                _depthRenderBufferId);
        checkGLError("FBO bind depth framebuffer");
    }

    if (!checkFramebufferStatus()) {
        // OK, if we have an error here - then throw an exception
        System.out.println("[Minecrift] FAILED to create framebuffer!!");
        throw new Exception("Failed to create framebuffer");
    }
}

From source file:com.mtbs3d.minecrift.FBOParams.java

License:LGPL

public void bindTexture() {
    OpenGlHelper.setActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(_textureType, _colorTextureId);
}