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:rtype.Prototyp.java

License:Open Source License

private void saveScreen() {
    GL11.glLoadIdentity();//  ww  w  .  j a  v  a2 s . c  om
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, SCREEN_TEXTURE_ID);
    GL11.glCopyTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, 0, 0, (int) SCREEN_WIDTH, (int) SCREEN_HEIGHT);

}

From source file:rtype.Prototyp.java

License:Open Source License

private void renderScanLines() {
    GL11.glLoadIdentity();/*  www  . ja v a2  s .c o m*/
    GL11.glTranslatef(0, 0, Prototyp.DEFAULT_Z);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureLoader.getTexture(IEntity.SCANLINE).getTextureId());
    GL11.glColor4f(1, 1, 1, 1);

    GL11.glBegin(GL11.GL_QUADS);
    GL11.glTexCoord2f(20, 0); //Upper right
    GL11.glVertex2f(SCREEN_WIDTH / 4, -SCREEN_HEIGHT / 4);

    GL11.glTexCoord2f(0, 0); //Upper left         
    GL11.glVertex2f(-SCREEN_WIDTH / 4, -SCREEN_HEIGHT / 4);

    GL11.glTexCoord2f(0, 20); //Lower left
    GL11.glVertex2f(-SCREEN_WIDTH / 4, SCREEN_HEIGHT / 4);

    GL11.glTexCoord2f(20, 20); // Lower right
    GL11.glVertex2f(SCREEN_WIDTH / 4, SCREEN_HEIGHT / 4);

    GL11.glEnd();
}

From source file:rtype.Prototyp.java

License:Open Source License

private void createOffScreenBuffer() {
    int bytesPerPixel = 3;
    ByteBuffer scratch = ByteBuffer.allocateDirect(1024 * 1024 * bytesPerPixel);
    IntBuffer buf = ByteBuffer.allocateDirect(12).order(ByteOrder.nativeOrder()).asIntBuffer();
    GL11.glGenTextures(buf); // Create Texture In OpenGL
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0));
    SCREEN_TEXTURE_ID = buf.get(0);// w  ww .  j a  v a 2 s . co  m

    int glType = GL11.GL_RGB;
    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.glTexImage2D(GL11.GL_TEXTURE_2D, 0, glType, 1024, 1024, 0, glType, GL11.GL_UNSIGNED_BYTE, scratch);

}

From source file:rtype.WorkAroundTextureLoader.java

License:Open Source License

private Texture loadTexture(String path, int xOffSet, int yOffSet, int textWidth, int textHeight) {

    BufferedImage buffImage = null;
    try {//from   w  w w  .  j av  a2 s .  com
        if (imageCache.get(path) != null)
            buffImage = (BufferedImage) imageCache.get(path);
        else {
            System.out.println("Loading image:" + path);
            buffImage = ImageIO.read(this.getClass().getResource(path));

            //February 2nd, 2011: Fix for JAVA 1.6 thanks to sonicWonder for the fix
            byte[] data = ((DataBufferByte) buffImage.getRaster().getDataBuffer()).getData();
            switch (buffImage.getType()) {
            case BufferedImage.TYPE_4BYTE_ABGR:
                convertFromARGBToBGRA(data);
                break;
            case BufferedImage.TYPE_3BYTE_BGR:
                convertFromBGRToRGB(data);
                break;
            default:
                System.out.println("Unknown type:" + buffImage.getType());
                break;
            }
            //End February 2nd, 2011: Fix for JAVA 1.6 thanks to sonicWonder for the fix
            imageCache.put(path, buffImage);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    int bytesPerPixel = buffImage.getColorModel().getPixelSize() / 8;

    ByteBuffer scratch = ByteBuffer.allocateDirect(textWidth * textHeight * bytesPerPixel)
            .order(ByteOrder.nativeOrder());

    DataBufferByte dataBufferByte = ((DataBufferByte) buffImage.getRaster().getDataBuffer());

    for (int i = 0; i < textHeight; i++)
        scratch.put(dataBufferByte.getData(), (xOffSet + (yOffSet + i) * buffImage.getWidth()) * bytesPerPixel,
                textWidth * bytesPerPixel);

    scratch.rewind();

    // Create A IntBuffer For Image Address In Memory
    IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
    GL11.glGenTextures(buf); // Create Texture In OpenGL

    // Create Nearest Filtered Texture
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0));
    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.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, textWidth, textHeight, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, scratch);

    Texture newTexture = new Texture();
    newTexture.textureId = buf.get(0); // Return Image Addresses In Memory
    newTexture.textureHeight = textHeight;
    newTexture.textureWidth = textWidth;

    return newTexture;
}

From source file:se.angergard.engine.graphics.FrameBuffer.java

License:Apache License

public FrameBuffer(int width, int height, boolean hasDepth, boolean hasStencil) {
    this.width = width;
    this.height = height;

    if ((width + height) % 4 != 0.0) {
        new Exception("Width + Height must be divisible by 4");
    }// www. j  ava2s  .c  om

    frameBufferID = GL30.glGenFramebuffers();
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBufferID);

    if (hasDepth && hasStencil) {
        depthAndStencilBufferID = GL30.glGenRenderbuffers();
        GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, depthAndStencilBufferID);
        GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL30.GL_DEPTH24_STENCIL8, width, height);
        GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_STENCIL_ATTACHMENT,
                GL30.GL_RENDERBUFFER, depthAndStencilBufferID);
        GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, 0);
    }

    else if (hasDepth) {
        depthBufferID = GL30.glGenRenderbuffers();
        GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, depthBufferID);
        GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL30.GL_DEPTH_COMPONENT32F, width, height);
        GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER,
                depthBufferID);
        GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, 0);
    }

    else if (hasStencil) {
        stencilBufferID = GL30.glGenRenderbuffers();
        GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, stencilBufferID);
        GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL30.GL_STENCIL_INDEX16, width, height);
        GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_STENCIL_ATTACHMENT, GL30.GL_RENDERBUFFER,
                stencilBufferID);
        GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, 0);
    }

    colorTexture = GL11.glGenTextures();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, colorTexture);
    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);
    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);

    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null);

    GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D,
            colorTexture, 0);

    int result = GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER);
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
    if (result != GL30.GL_FRAMEBUFFER_COMPLETE) {
        if (result == GL30.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT) {
            new Exception("Frame Buffer Error: incomplete attachment").printStackTrace();
        }
        if (result == GL30.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER) {
            new Exception("Frame Buffer Error: incomplete draw buffer").printStackTrace();
        }
        if (result == GL30.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT) {
            new Exception("Frame Buffer Error: missing attachment").printStackTrace();
        }
        if (result == GL30.GL_FRAMEBUFFER_UNSUPPORTED) {
            new Exception("Frame Buffer Error: unsupported combination of formats").printStackTrace();
        }
        if (result == GL30.GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE) {
            new Exception("Frame Buffer Error: incomplete multisample").printStackTrace();
        }
        if (result == GL30.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER) {
            new Exception("Frame Buffer Error: incomplete read buffer").printStackTrace();
        }

        new Exception("frame buffer couldn't be constructed: unknown error " + result).printStackTrace();
    }
    RenderUtil.unbindFrameBuffer();
    RenderUtil.unbindTexture();

    frameBufferShader = new ShaderProgram().createDefault2DShader();
}

From source file:se.angergard.engine.graphics.Texture.java

License:Apache License

private void loadTexture(ByteBuffer buffer, int textureID, int width, int height) {
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);

    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);

    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, buffer);

    // Not all computer will support this, fix //TODO
    GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);

    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_MAG_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
}

From source file:se.angergard.engine.graphics.Texture.java

License:Apache License

/** Bind the Texture ID to the graphic's card */
public void bind() {
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, TEXTURE_ID);
}

From source file:shadowmage.meim.client.gui.GuiTextureElement.java

License:Open Source License

private void bindTexture() {
    prevTexNum = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, openGLTextureNumber);
}

From source file:shadowmage.meim.client.gui.GuiTextureElement.java

License:Open Source License

public void resetBoundTexture() {
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, prevTexNum);
}

From source file:shadowmage.meim.client.texture.TextureManager.java

License:Open Source License

public static void bindTexture() {
    prevTexNum = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texNum);
}