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.flowpowered.caustic.lwjgl.gl30.GL30Texture.java

License:MIT License

@Override
public void setImageData(ByteBuffer imageData, int width, int height) {
    checkCreated();/*ww w  .  java 2s.  com*/
    if (width <= 0) {
        throw new IllegalArgumentException("Width must be greater than zero");
    }
    if (height <= 0) {
        throw new IllegalArgumentException("Height must be greater than zero");
    }
    // Back up the old values
    int oldWidth = this.width;
    int oldHeight = this.height;
    // Update the texture width and height
    this.width = width;
    this.height = height;
    // Bind the texture
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);
    // Use byte alignment
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
    // Upload the texture
    final boolean hasInternalFormat = internalFormat != null;
    // Check if we can only upload without reallocating
    if (imageData != null && width == oldWidth && height == oldHeight) {
        GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, width, height, format.getGLConstant(),
                hasInternalFormat ? internalFormat.getComponentType().getGLConstant()
                        : DataType.UNSIGNED_BYTE.getGLConstant(),
                imageData);
    } else {
        // Reallocate and upload the image
        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0,
                hasInternalFormat ? internalFormat.getGLConstant() : format.getGLConstant(), width, height, 0,
                format.getGLConstant(), hasInternalFormat ? internalFormat.getComponentType().getGLConstant()
                        : DataType.UNSIGNED_BYTE.getGLConstant(),
                imageData);
    }
    // Generate mipmaps if necessary
    if (minFilter.needsMipMaps() && imageData != null) {
        GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
    }
    // Unbind the texture
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
    // Check for errors
    LWJGLUtil.checkForGLError();
}

From source file:com.github.begla.blockmania.world.horizon.Skysphere.java

License:Apache License

public void render() {
    updateClouds();//ww  w.  j  av  a2 s  .c  o  m

    glDisable(GL_CULL_FACE);
    glDisable(GL_DEPTH_TEST);

    glEnable(GL13.GL_TEXTURE_CUBE_MAP);
    GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, _textureIds.get(0));
    _sunPosAngle = (float) Math.toRadians(360.0 * _parent.getWorldProvider().getTime() - 90.0);
    Vector4f sunNormalise = new Vector4f(0.0f, (float) Math.cos(_sunPosAngle), (float) Math.sin(_sunPosAngle),
            1.0f);
    sunNormalise.normalize();

    _zenithColor = getAllWeatherZenith(sunNormalise.y);

    ShaderManager.getInstance().enableShader("sky");

    int sunPos = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("sky"), "sunPos");
    GL20.glUniform4f(sunPos, 0.0f, (float) Math.cos(_sunPosAngle), (float) Math.sin(_sunPosAngle), 1.0f);

    int time = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("sky"), "time");
    GL20.glUniform1f(time, (float) _parent.getWorldProvider().getTime());

    int sunAngle = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("sky"), "sunAngle");
    GL20.glUniform1f(sunAngle, _sunPosAngle);

    int turbidity = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("sky"), "turbidity");
    GL20.glUniform1f(turbidity, _turbidity);

    int zenith = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("sky"), "zenith");
    GL20.glUniform3f(zenith, _zenithColor.x, _zenithColor.y, _zenithColor.z);

    // DRAW THE SKYSPHERE
    drawSphere();

    glDisable(GL13.GL_TEXTURE_CUBE_MAP);

    ShaderManager.getInstance().enableShader("clouds");
    // Apply daylight
    int lightClouds = GL20.glGetUniformLocation(ShaderManager.getInstance().getShader("clouds"), "light");
    GL20.glUniform1f(lightClouds, getDaylight());

    // DRAW THE CLOUDS
    drawClouds();
    ShaderManager.getInstance().enableShader(null);

    glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
}

From source file:com.github.begla.blockmania.world.horizon.Skysphere.java

License:Apache License

private void loadStarTextures() {
    int internalFormat = GL11.GL_RGBA8, format = GL12.GL_BGRA;

    GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, _textureIds.get(0));

    GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL12.GL_TEXTURE_WRAP_R, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);

    for (int i = 0; i < 6; i++) {

        byte[] data = TextureManager.getInstance().getTexture("stars" + (i + 1)).getTextureData();
        ByteBuffer byteBuffer = BufferUtils.createByteBuffer(data.length);
        byteBuffer.put(data);/*from  ww  w  .  j ava  2  s  .c o  m*/
        byteBuffer.flip();

        GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, internalFormat, 256, 256, 0, format,
                GL11.GL_UNSIGNED_BYTE, byteBuffer);
    }
}

From source file:com.github.jtse.puzzle.ogl.Textures.java

License:Apache License

public static void renderImage(Texture texture, int x, int y, int z) {
    // Color.white.bind();
    // texture.bind(); // or GL11.glBind(texture.getTextureID());
    //GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    GL11.glBindTexture(GL_TEXTURE_2D, texture.getTextureID());

    // GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE,
    // GL11.GL_MODULATE );

    // when texture area is small, bilinear filter the closest mipmap

    // GL11.glTexParameterf( GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER,
    // GL11.GL_LINEAR_MIPMAP_NEAREST );
    // when texture area is large, bilinear filter the first mipmap
    // GL11.glTexParameterf( GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER,
    // GL11.GL_LINEAR );

    // GL11.glTexParameterf( GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S,
    // GL11.GL_CLAMP );
    // GL11.glTexParameterf( GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T,
    // GL11.GL_CLAMP );

    glBegin(GL11.GL_QUADS);//from  ww w  .ja v a 2s  .co  m

    GL11.glTexCoord2d(0.0d, 0.0d);
    GL11.glVertex3d(x, y, z);

    // It's 0.99 instead of 1.0 because 1.0 creates edge artifacts
    GL11.glTexCoord2d(0.99d, 0.0d);
    GL11.glVertex3d(x + texture.getTextureWidth(), y, z);

    GL11.glTexCoord2d(0.99d, 0.99d);
    GL11.glVertex3d(x + texture.getTextureWidth(), y + texture.getTextureHeight(), z);

    GL11.glTexCoord2d(0.0d, 0.99d);
    GL11.glVertex3d(x, y + texture.getTextureHeight(), z);

    glEnd();
}

From source file:com.github.kajdreef.mazerunnermvn.Object.GameObject.java

/**
 * Render the Object.//  w  ww .  j a va2 s .c om
 */
public void render() {
    FloatBuffer matrix44Buffer = BufferUtils.createFloatBuffer(16);
    modelMatrix.store(matrix44Buffer);
    matrix44Buffer.flip();
    GL20.glUniformMatrix4(ShaderProgram.getMML(), false, matrix44Buffer);

    // Bind the texture
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);

    // Bind to the VAO that has all the information about the quad vertices
    GL30.glBindVertexArray(vaoId);
    GL20.glEnableVertexAttribArray(0);
    GL20.glEnableVertexAttribArray(1);
    GL20.glEnableVertexAttribArray(2);

    // Bind to the index VBO that has all the information about the order of the vertices
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboIndicesId);

    // Draw the vertices
    GL11.glDrawElements(GL11.GL_TRIANGLES, indicesData.length, GL11.GL_UNSIGNED_BYTE, 0);

    // Put everything back to default (deselect)
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL20.glDisableVertexAttribArray(2);
    GL20.glDisableVertexAttribArray(1);
    GL20.glDisableVertexAttribArray(0);
    GL30.glBindVertexArray(0);
}

From source file:com.github.kajdreef.mazerunnermvn.Object.GameObject.java

protected void setTextureUnit(Texture texture, int textureUnit) {
    // Create a new texture object in memory and bind it
    texId = GL11.glGenTextures();/*  w w w.  j  ava  2  s.c om*/
    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, texture.getWidth(), texture.getHeight(), 0,
            GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, texture.getTexBuffer());
    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_LINEAR_MIPMAP_LINEAR);
}

From source file:com.golden.gamedev.engine.lwjgl.Texture.java

License:Open Source License

/**
 * Bind the specified GL context to a texture.
 * /* ww  w.  java 2  s .  c om*/
 * @param gl the GL context to bind to
 */
public void bind() {
    GL11.glBindTexture(this.target, this.textureID);
}

From source file:com.golden.gamedev.engine.lwjgl.TextureLoader.java

License:Open Source License

/**
 * Load a texture into OpenGL from a image reference on disk.
 * //  w  w  w.j  a  v  a 2 s  .  c om
 * @param resourceName The location of the resource to load
 * @param target The GL target to load the texture against
 * @param dstPixelFormat The pixel format of the screen
 * @param minFilter The minimising filter
 * @param magFilter The magnification filter
 * @return The loaded texture
 * @throws IOException Indicates a failure to access the resource
 */
public Texture getTexture(BufferedImage image, int target, int dstPixelFormat, int minFilter, int magFilter) {
    int srcPixelFormat = 0;

    // create the texture ID for this texture
    int textureID = this.createTextureID();
    Texture texture = new Texture(target, textureID);

    // bind this texture
    GL11.glBindTexture(target, textureID);

    texture.setWidth(image.getWidth());
    texture.setHeight(image.getHeight());

    srcPixelFormat = (image.getColorModel().hasAlpha()) ? GL11.GL_RGBA : GL11.GL_RGB;

    // convert that image into a byte buffer of texture data
    ByteBuffer textureBuffer = this.convertImageData(image, texture);

    if (target == GL11.GL_TEXTURE_2D) {
        GL11.glTexParameteri(target, GL11.GL_TEXTURE_MIN_FILTER, minFilter);
        GL11.glTexParameteri(target, GL11.GL_TEXTURE_MAG_FILTER, magFilter);
    }

    // produce a texture from the byte buffer
    GL11.glTexImage2D(target, 0, dstPixelFormat, this.get2Fold(image.getWidth()),
            this.get2Fold(image.getHeight()), 0, srcPixelFormat, GL11.GL_UNSIGNED_BYTE, textureBuffer);

    return texture;
}

From source file:com.google.gapid.glviewer.gl.Texture.java

License:Apache License

void bind() {
    GL11.glBindTexture(target, handle);
}

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

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