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.voxelplugineering.voxelsniper.render.RenderMain.java

License:Open Source License

public void tick() {
    if (!setup) {
        return;/*  w  w  w .  j a v  a 2s .  c  o m*/
    }
    Camera camera = Standalone.system().getMainCamera();

    // reset view matrix
    viewMatrix.setIdentity();

    // Translate camera
    Vector3f rot = camera.getCameraRot();
    Matrix4f.rotate(rot.x, new Vector3f(1, 0, 0), viewMatrix, viewMatrix);
    Matrix4f.rotate(rot.y, new Vector3f(0, 1, 0), viewMatrix, viewMatrix);
    Matrix4f.rotate(rot.z, new Vector3f(0, 0, 1), viewMatrix, viewMatrix);
    Matrix4f.translate(camera.getCameraPos(), viewMatrix, viewMatrix);

    GL20.glUseProgram(pId);

    // push matrices
    viewMatrix.store(matrix44Buffer);
    matrix44Buffer.flip();
    GL20.glUniformMatrix4(viewMatrixLocation, false, matrix44Buffer);
    modelMatrix.store(matrix44Buffer);
    matrix44Buffer.flip();
    GL20.glUniformMatrix4(modelMatrixLocation, false, matrix44Buffer);
    projectionMatrix.store(matrix44Buffer);
    matrix44Buffer.flip();
    GL20.glUniformMatrix4(projectionMatrixLocation, false, matrix44Buffer);

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

    // bind textures
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.textures.get("block"));

    // render all buffer sections
    buffer.renderSections();

    GL20.glUseProgram(0);

    OpenGLUtilities.checkGLError("render main");

    Display.update();
}

From source file:com.voxelplugineering.voxelsniper.util.TextureUtilities.java

License:Open Source License

public static int loadPNGTexture(File file, int textureUnit) {
    ByteBuffer buf = null;//from  ww  w . j a va 2  s.  c  o  m
    int tWidth = 0;
    int tHeight = 0;

    try {
        BufferedImage image = ImageIO.read(file);
        tWidth = image.getWidth();
        tHeight = image.getHeight();
        buf = imageToRGBABuffer(image);
    } catch (IOException e) {
        e.printStackTrace();
        if (file.getName().endsWith("debug.png")) {
            System.exit(-1);
        } else {
            return debugTexture;
        }
    }

    // Create a new texture object in memory and bind it
    int texId = GL11.glGenTextures();
    GL13.glActiveTexture(textureUnit);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);

    // All RGB bytes are aligned to each other and each component is 1 byte
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);

    // Upload the texture data and generate mip maps (for scaling)
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, tWidth, tHeight, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, buf);
    GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);

    // Setup the ST coordinate system
    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);

    // Setup what to do when the texture has to be scaled
    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_MIPMAP_NEAREST);

    OpenGLUtilities.checkGLError("loadPNGTexture");
    if (file.getName().endsWith("debug.png")) {
        debugTexture = texId;
    }
    return texId;
}

From source file:com.xrbpowered.gl.examples.GLLife.java

License:Open Source License

private void resetBuffers(boolean fill) {
    if (buffers[0] != null)
        buffers[0].destroy();/*from  ww w .  j a v  a  2  s  .c  o  m*/
    if (buffers[1] != null)
        buffers[1].destroy();

    int width = getTargetWidth();
    int height = getTargetHeight();
    buffers[0] = new OffscreenBuffers(width, height, false);
    buffers[1] = new OffscreenBuffers(width, height, false);
    targetBuffer = 1;
    turn = 0;

    IntBuffer intBuffer = ByteBuffer.allocateDirect(4 * width * height).order(ByteOrder.nativeOrder())
            .asIntBuffer();
    int[] pixels = new int[width * height];
    for (int x = 1; x < width; x++)
        for (int y = 1; y < height; y++) {
            int v = fill && random.nextInt(27) == 0 ? 0xffffffff : 0xff000000;
            pixels[y * width + x] = v;
        }
    intBuffer.put(pixels);
    intBuffer.flip();

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, buffers[0].getColorTexId());
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL12.GL_BGRA,
            GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intBuffer);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, buffers[1].getColorTexId());
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL12.GL_BGRA,
            GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intBuffer);
}

From source file:com.xrbpowered.gl.examples.GLLife.java

License:Open Source License

private void addGlider(int x, int y, int width, int height, int[] pixels) {
    IntBuffer intBuffer = ByteBuffer.allocateDirect(4 * width * height).order(ByteOrder.nativeOrder())
            .asIntBuffer();/*from   w  w w .  j  a v a2s .c o  m*/
    intBuffer.put(pixels);
    intBuffer.flip();

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, buffers[1 - targetBuffer].getColorTexId());
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
    GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, x, y, width, height, GL12.GL_BGRA,
            GL12.GL_UNSIGNED_INT_8_8_8_8_REV, intBuffer);
}

From source file:com.xrbpowered.gl.res.buffers.MultisampleBuffers.java

License:Open Source License

protected void create(int w, int h, int samples, boolean depthBuffer, boolean hdr) {
    colorMSTexId = GL11.glGenTextures();
    GL11.glBindTexture(GL32.GL_TEXTURE_2D_MULTISAMPLE, colorMSTexId);
    GL32.glTexImage2DMultisample(GL32.GL_TEXTURE_2D_MULTISAMPLE, samples, hdr ? GL30.GL_RGB16F : GL11.GL_RGB, w,
            h, false);//from w  w  w  . ja v  a  2 s  .  co  m
    GL11.glBindTexture(GL32.GL_TEXTURE_2D_MULTISAMPLE, 0);
    GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, colorMSTexId, 0);

    depthMSTexId = 0;
    if (depthBuffer) {
        depthMSTexId = GL11.glGenTextures();
        GL11.glBindTexture(GL32.GL_TEXTURE_2D_MULTISAMPLE, depthMSTexId);
        GL32.glTexImage2DMultisample(GL32.GL_TEXTURE_2D_MULTISAMPLE, samples, GL30.GL_DEPTH24_STENCIL8, w, h,
                false);
        GL11.glBindTexture(GL32.GL_TEXTURE_2D_MULTISAMPLE, 0);
        GL32.glFramebufferTexture(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, depthMSTexId, 0);
    }
    checkStatus();
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
}

From source file:com.xrbpowered.gl.res.buffers.OffscreenBuffers.java

License:Open Source License

protected void create(int w, int h, boolean depthBuffer, boolean hdr) {
    colorTexId = GL11.glGenTextures();// w  ww.  j a v a 2  s  .  com
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, colorTexId);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, hdr ? GL30.GL_RGB16F : GL11.GL_RGB, w, h, 0, GL11.GL_RGB,
            GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
    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.glBindTexture(GL11.GL_TEXTURE_2D, 0);
    GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, colorTexId,
            0);

    depthTexId = 0;
    if (depthBuffer) {
        depthTexId = GL11.glGenTextures();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, depthTexId);
        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT16, w, h, 0, GL11.GL_DEPTH_COMPONENT,
                GL11.GL_FLOAT, (ByteBuffer) null);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
        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.glBindTexture(GL11.GL_TEXTURE_2D, 0);
        GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL11.GL_TEXTURE_2D,
                depthTexId, 0);
    }
    checkStatus();
    GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
}

From source file:com.xrbpowered.gl.res.buffers.OffscreenBuffers.java

License:Open Source License

public void bindColorBuffer(int index) {
    GL13.glActiveTexture(GL13.GL_TEXTURE0 + index);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, colorTexId);
}

From source file:com.xrbpowered.gl.res.buffers.OffscreenBuffers.java

License:Open Source License

public void bindDepthBuffer(int index) {
    if (depthTexId > 0) {
        GL13.glActiveTexture(GL13.GL_TEXTURE0 + index);
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, depthTexId);
    }/*from w  ww.jav  a 2  s.c  o  m*/
}

From source file:com.xrbpowered.gl.res.SkyBox.java

License:Open Source License

public void draw() {
    shader.use();
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, texture.getId());
    cube.draw();
    shader.unuse();
}

From source file:com.xrbpowered.gl.res.textures.ArrayTexture.java

License:Open Source License

public ArrayTexture(int w, int h, int layers) {
    this.width = w;
    this.height = h;
    this.layers = layers;

    texId = GL11.glGenTextures();/*from ww w.j ava 2s.com*/
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, texId);
    intBuffer = ByteBuffer.allocateDirect(4 * w * h * layers).order(ByteOrder.nativeOrder()).asIntBuffer();
}