Example usage for org.lwjgl.opengl GL11 glTexImage2D

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

Introduction

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

Prototype

public static void glTexImage2D(@NativeType("GLenum") int target, @NativeType("GLint") int level,
        @NativeType("GLint") int internalformat, @NativeType("GLsizei") int width,
        @NativeType("GLsizei") int height, @NativeType("GLint") int border, @NativeType("GLenum") int format,
        @NativeType("GLenum") int type, @Nullable @NativeType("void const *") double[] pixels) 

Source Link

Document

Array version of: #glTexImage2D TexImage2D

Usage

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

License:MIT License

public static int loadTexture(int[] rgb, int width, int height) {
    IntBuffer rgbBuf = BufferUtils.createIntBuffer(rgb.length);
    rgbBuf.put(rgb);//from ww w . j  a  va2 s . c o  m
    rgbBuf.flip();

    int tex = GL11.glGenTextures();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL12.GL_BGRA,
            GL12.GL_UNSIGNED_INT_8_8_8_8_REV, rgbBuf);
    return tex;
}

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

License:MIT License

public static void loadTextureMipmap(int tex, int[] rgb, int width, int height) {
    IntBuffer rgbBuf = BufferUtils.createIntBuffer(rgb.length);
    rgbBuf.put(rgb);//from ww  w.j  ava 2s  . c  o m
    rgbBuf.flip();

    bind(tex);

    //If OpenGL30, use glGenerateMipmap, else use the GL_GENERATE_MIPMAP tex param
    if (RenderUtil.GL_30) {
        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL12.GL_BGRA,
                GL12.GL_UNSIGNED_INT_8_8_8_8_REV, rgbBuf);
        GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
    } else {
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL12.GL_BGRA,
                GL12.GL_UNSIGNED_INT_8_8_8_8_REV, rgbBuf);
    }
}

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 .j  a 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  .  j av  a 2s.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.
 * /*ww  w.  j  a  va 2s.  c  o m*/
 * @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.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
 *///from w  w  w .  j a  va  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);
}

From source file:net.minecraft.src.PaintWorld.java

License:Open Source License

public void getTextureForFace(int face) {
    PaintFace pface = renderBlock.paintedFaces[face];
    if (textureBuffer == null) {
        textureBuffer = ByteBuffer.allocateDirect(ARRAY_SIZE);
        textureBuffer.order(ByteOrder.nativeOrder());
    }/*from  ww  w.  j a v  a  2s.com*/
    if (textureId <= 0) {
        textureId = GL11.glGenTextures();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
        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, textureId);
    textureBuffer.clear();
    textureBuffer.put(pface.points);
    textureBuffer.flip();
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, ROW, ROW, 0, GL11.GL_RGBA, GL11.GL_BYTE,
            textureBuffer);
}

From source file:net.neilcsmith.praxis.video.opengl.internal.Texture.java

License:Apache License

private void init() {
    glHandle = createGLHandle();/*from w  w  w  . j a  v  a 2 s .co m*/
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, glHandle);
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, dstImageFormat, width, height, 0, GL12.GL_BGRA,
            GL12.GL_UNSIGNED_INT_8_8_8_8_REV, BufferUtils.createIntBuffer(width * height));
    setFilter(minFilter, magFilter);
    setWrap(uWrap, vWrap);
    getFrameBuffer();
}

From source file:net.smert.frameworkgl.opengl.helpers.TextureHelper.java

License:Apache License

public void setImage2DBytePixelData(int internalFormat, int width, int height, int format,
        ByteBuffer pixelData) {/*from  w  ww .  j a va 2  s  . c o m*/
    GL11.glTexImage2D(textureTarget, 0, internalFormat, width, height, 0, format, TextureTypes.UNSIGNED_BYTE,
            pixelData);
}

From source file:net.smert.frameworkgl.opengl.helpers.TextureHelper.java

License:Apache License

public void setImage2DFloatPixelData(int internalFormat, int width, int height, int format,
        FloatBuffer pixelData) {//  w  w  w .  ja v a  2  s  .c om
    GL11.glTexImage2D(textureTarget, 0, internalFormat, width, height, 0, format, TextureTypes.FLOAT,
            pixelData);
}