Example usage for org.lwjgl.opengl GL11 glTexParameteri

List of usage examples for org.lwjgl.opengl GL11 glTexParameteri

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL11 glTexParameteri.

Prototype

public static void glTexParameteri(@NativeType("GLenum") int target, @NativeType("GLenum") int pname,
        @NativeType("GLint") int param) 

Source Link

Document

Sets the integer value of a texture parameter, which controls how the texel array is treated when specified or changed, and when applied to a fragment.

Usage

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

License:MIT License

public static void setMinFilter(int filter) {
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filter);
}

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

License:MIT License

public static void setMagFilter(int filter) {
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, filter);
}

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

License:MIT License

public static void setWrapS(int wrap) {
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, wrap);
}

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

License:MIT License

public static void setWrapT(int wrap) {
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, wrap);
}

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

License:Open Source License

@Override
public void setTextureFilter(int textureFilter) {
    this.bind();/*w w  w  .j a  v a2  s .c o  m*/
    GL11.glTexParameteri(this.target, GL11.GL_TEXTURE_MIN_FILTER, textureFilter);
    GL11.glTexParameteri(this.target, GL11.GL_TEXTURE_MAG_FILTER, textureFilter);
}

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

License:Open Source License

private TextureImplementation getTexture(InputStream in, String resourceName, int target, int minFilter,
        int magFilter, boolean flipped, int[] transparent) throws IOException {
    // create the texture ID for this texture
    ByteBuffer textureBuffer;//from  w w  w .ja v a  2  s  . c om

    LoadableImageData imageData = ImageDataFactory.getImageDataFor(resourceName);
    textureBuffer = imageData.loadImage(new BufferedInputStream(in), flipped, transparent);

    int textureID = createTextureID();
    TextureImplementation texture = new TextureImplementation(resourceName, target, textureID);
    // bind this texture
    GL11.glEnable(target);
    GL11.glBindTexture(target, textureID);

    int width;
    int height;
    int texWidth;
    int texHeight;

    ImageData.Format format;

    width = imageData.getWidth();
    height = imageData.getHeight();
    format = imageData.getFormat();

    texture.setTextureWidth(imageData.getTexWidth());
    texture.setTextureHeight(imageData.getTexHeight());

    texWidth = texture.getTextureWidth();
    texHeight = texture.getTextureHeight();

    IntBuffer temp = BufferUtils.createIntBuffer(16);
    GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE, temp);
    int max = temp.get(0);
    if (texWidth > max || texHeight > max)
        throw new IOException("Attempt to allocate a texture to big for the current hardware");

    int srcPixelFormat = format.getOGLType();

    texture.setWidth(width);
    texture.setHeight(height);
    texture.setImageFormat(format);

    GL11.glTexParameteri(target, GL11.GL_TEXTURE_MIN_FILTER, minFilter);
    GL11.glTexParameteri(target, GL11.GL_TEXTURE_MAG_FILTER, magFilter);

    ContextCapabilities capabilities = GLContext.getCapabilities();

    if (capabilities.OpenGL30 || capabilities.GL_EXT_framebuffer_object
            || capabilities.GL_ARB_framebuffer_object || capabilities.OpenGL14) {
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LOD, GL11.GL_POLYGON_BIT);
        if (capabilities.OpenGL30)
            GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
        else if (capabilities.GL_EXT_framebuffer_object)
            EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_2D);
        else if (capabilities.GL_ARB_framebuffer_object)
            ARBFramebufferObject.glGenerateMipmap(GL11.GL_TEXTURE_2D);
        else if (capabilities.OpenGL14)
            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
    }

    // produce a texture from the byte buffer
    GL11.glTexImage2D(target, 0, this.dstPixelFormat, get2Fold(width), get2Fold(height), 0, srcPixelFormat,
            GL11.GL_UNSIGNED_BYTE, textureBuffer);
    return texture;
}

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

License:Open Source License

/**
 * Get a texture from an image file./*  w ww . java 2 s  .co m*/
 * 
 * @param dataSource The image data to generate the texture from
 * @param filter The filter to use when scaling the texture
 * @return The texture created
 * @throws IOException Indicates the texture is too big for the hardware
 */
public Texture getTexture(ImageData dataSource, int filter) throws IOException {
    int target = GL11.GL_TEXTURE_2D;

    ByteBuffer textureBuffer;
    textureBuffer = dataSource.getImageBufferData();

    // create the texture ID for this texture
    int textureID = createTextureID();
    TextureImplementation texture = new TextureImplementation("generated:" + dataSource, target, textureID);

    int minFilter = filter;
    int magFilter = filter;

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

    int width;
    int height;
    int texWidth;
    int texHeight;

    ImageData.Format format;

    width = dataSource.getWidth();
    height = dataSource.getHeight();
    format = dataSource.getFormat();

    texture.setTextureWidth(dataSource.getTexWidth());
    texture.setTextureHeight(dataSource.getTexHeight());

    texWidth = texture.getTextureWidth();
    texHeight = texture.getTextureHeight();

    int srcPixelFormat = format.getOGLType();

    texture.setWidth(width);
    texture.setHeight(height);
    texture.setImageFormat(format);

    IntBuffer temp = BufferUtils.createIntBuffer(16);
    GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE, temp);
    int max = temp.get(0);
    if (texWidth > max || texHeight > max)
        throw new IOException("Attempt to allocate a texture to big for the current hardware");

    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, this.dstPixelFormat, get2Fold(width), get2Fold(height), 0, srcPixelFormat,
            GL11.GL_UNSIGNED_BYTE, textureBuffer);
    return texture;
}

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

License:Open Source License

/**
 * Reload a given texture blob; used internally with setHoldTextureData. Call TextureImpl.reload instead.
 * //from   ww  w  .  j  a  va  2 s  .  com
 * @param texture The texture being reloaded
 * @param srcPixelFormat The source pixel format
 * @param componentCount The component count
 * @param minFilter The minification filter
 * @param magFilter The magnification filter
 * @param textureBuffer The pixel data
 * @return The ID of the newly created texture
 */
public int reload(TextureImplementation texture, int srcPixelFormat, int componentCount, int minFilter,
        int magFilter, ByteBuffer textureBuffer) {
    int target = GL11.GL_TEXTURE_2D;
    int textureID = createTextureID();
    GL11.glEnable(target);
    GL11.glBindTexture(target, textureID);

    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, this.dstPixelFormat, texture.getTextureWidth(), texture.getTextureHeight(), 0,
            srcPixelFormat, GL11.GL_UNSIGNED_BYTE, textureBuffer);
    return textureID;
}

From source file:net.BiggerOnTheInside.Binder.BlockRenderer.java

License:Open Source License

public static void renderBlock(Block b, float x, float y, float z) {
    GL11.glPushMatrix();//from   w w w  . j  a va2s . c  o m
    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.glTranslatef(x * 2f, y * 2f, z * 2f);
    GL11.glBegin(GL11.GL_QUADS);
    GL11.glColor3f(1f, 1f, 1f);

    // Top face.
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Top).x(), b.getTextureCoordinates(BlockFace.Top).y());
    GL11.glVertex3f(1.0f, 1.0f, -1.0f);
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Top).x() + Globals.TEXTURE_SIZE,
            b.getTextureCoordinates(BlockFace.Top).y());
    GL11.glVertex3f(-1.0f, 1.0f, -1.0f);
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Top).x() + Globals.TEXTURE_SIZE,
            b.getTextureCoordinates(BlockFace.Top).y() + Globals.TEXTURE_SIZE);
    GL11.glVertex3f(-1.0f, 1.0f, 1.0f);
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Top).x(),
            b.getTextureCoordinates(BlockFace.Top).y() + Globals.TEXTURE_SIZE);
    GL11.glVertex3f(1.0f, 1.0f, 1.0f);

    // Bottom.
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Bottom).x(),
            b.getTextureCoordinates(BlockFace.Bottom).y());
    GL11.glVertex3f(1.0f, -1.0f, 1.0f);
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Bottom).x() + Globals.TEXTURE_SIZE,
            b.getTextureCoordinates(BlockFace.Bottom).y());
    GL11.glVertex3f(-1.0f, -1.0f, 1.0f);
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Bottom).x() + Globals.TEXTURE_SIZE,
            b.getTextureCoordinates(BlockFace.Bottom).y() + Globals.TEXTURE_SIZE);
    GL11.glVertex3f(-1.0f, -1.0f, -1.0f);
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Bottom).x(),
            b.getTextureCoordinates(BlockFace.Bottom).y() + Globals.TEXTURE_SIZE);
    GL11.glVertex3f(1.0f, -1.0f, -1.0f);

    // Front.
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Front).x(),
            b.getTextureCoordinates(BlockFace.Front).y());
    GL11.glVertex3f(1.0f, 1.0f, 1.0f);
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Front).x() + Globals.TEXTURE_SIZE,
            b.getTextureCoordinates(BlockFace.Front).y());
    GL11.glVertex3f(-1.0f, 1.0f, 1.0f);
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Front).x() + Globals.TEXTURE_SIZE,
            b.getTextureCoordinates(BlockFace.Front).y() + Globals.TEXTURE_SIZE);
    GL11.glVertex3f(-1.0f, -1.0f, 1.0f);
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Front).x(),
            b.getTextureCoordinates(BlockFace.Front).y() + Globals.TEXTURE_SIZE);
    GL11.glVertex3f(1.0f, -1.0f, 1.0f);

    // Back.
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Back).x(), b.getTextureCoordinates(BlockFace.Back).y());
    GL11.glVertex3f(1.0f, -1.0f, -1.0f);
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Back).x() + Globals.TEXTURE_SIZE,
            b.getTextureCoordinates(BlockFace.Back).y());
    GL11.glVertex3f(-1.0f, -1.0f, -1.0f);
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Back).x() + Globals.TEXTURE_SIZE,
            b.getTextureCoordinates(BlockFace.Back).y() + Globals.TEXTURE_SIZE);
    GL11.glVertex3f(-1.0f, 1.0f, -1.0f);
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Back).x(),
            b.getTextureCoordinates(BlockFace.Back).y() + Globals.TEXTURE_SIZE);
    GL11.glVertex3f(1.0f, 1.0f, -1.0f);

    // Left
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Left).x(), b.getTextureCoordinates(BlockFace.Left).y());
    GL11.glVertex3f(-1.0f, 1.0f, 1.0f);
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Left).x() + Globals.TEXTURE_SIZE,
            b.getTextureCoordinates(BlockFace.Left).y());
    GL11.glVertex3f(-1.0f, 1.0f, -1.0f);
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Left).x() + Globals.TEXTURE_SIZE,
            b.getTextureCoordinates(BlockFace.Left).y() + Globals.TEXTURE_SIZE);
    GL11.glVertex3f(-1.0f, -1.0f, -1.0f);
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Left).x(),
            b.getTextureCoordinates(BlockFace.Left).y() + Globals.TEXTURE_SIZE);
    GL11.glVertex3f(-1.0f, -1.0f, 1.0f);

    // Right.
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Right).x(),
            b.getTextureCoordinates(BlockFace.Right).y());
    GL11.glVertex3f(1.0f, 1.0f, -1.0f);
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Right).x() + Globals.TEXTURE_SIZE,
            b.getTextureCoordinates(BlockFace.Right).y());
    GL11.glVertex3f(1.0f, 1.0f, 1.0f);
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Right).x() + Globals.TEXTURE_SIZE,
            b.getTextureCoordinates(BlockFace.Right).y() + Globals.TEXTURE_SIZE);
    GL11.glVertex3f(1.0f, -1.0f, 1.0f);
    GL11.glTexCoord2f(b.getTextureCoordinates(BlockFace.Right).x(),
            b.getTextureCoordinates(BlockFace.Right).y() + Globals.TEXTURE_SIZE);
    GL11.glVertex3f(1.0f, -1.0f, -1.0f);
    GL11.glEnd();
    GL11.glTranslatef(0f, 0f, 0f);
    GL11.glPopMatrix();
}

From source file:net.minecraft.client.gui.fonts.GlyphCache.java

License:Open Source License

/**
 * Allocate a new OpenGL texture for caching pre-rendered glyph images. The
 * new texture is initialized to fully transparent white so the individual
 * glyphs images within can have a transparent border between them. The new
 * texture remains bound after returning from the function.
 *
 * @todo use GL_ALPHA4 if anti-alias is turned off for even smaller textures
 *//*ww  w .  ja v a 2 s .  c om*/
private void allocateGlyphCacheTexture() {
    /* Initialize the background to all white but fully transparent. */
    glyphCacheGraphics.clearRect(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT);

    /* Allocate new OpenGL texure */
    singleIntBuffer.clear();
    GLAllocation.generateTextureNames(singleIntBuffer);
    textureName = singleIntBuffer.get(0);

    /* Load imageBuffer with pixel data ready for transfer to OpenGL texture */
    updateImageBuffer(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT);

    /*
     * Initialize texture with the now cleared BufferedImage. Using a texture with GL_ALPHA8 internal format may result in
     * faster rendering since the GPU has to only fetch 1 byte per texel instead of 4 with a regular RGBA texture.
     */
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureName);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_ALPHA8, TEXTURE_WIDTH, TEXTURE_HEIGHT, 0, GL11.GL_RGBA,
            GL11.GL_UNSIGNED_BYTE, imageBuffer);

    /* Explicitely disable mipmap support becuase updateTexture() will only update the base level 0 */
    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);
}