Example usage for org.lwjgl.opengl GL14 GL_GENERATE_MIPMAP

List of usage examples for org.lwjgl.opengl GL14 GL_GENERATE_MIPMAP

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL14 GL_GENERATE_MIPMAP.

Prototype

int GL_GENERATE_MIPMAP

To view the source code for org.lwjgl.opengl GL14 GL_GENERATE_MIPMAP.

Click Source Link

Document

Accepted by the pname parameter of TexParameteri, TexParameterf, TexParameteriv, TexParameterfv, GetTexParameteriv, and GetTexParameterfv.

Usage

From source file:cuchaz.jfxgl.prism.JFXGLContext.java

License:Open Source License

@Override
public boolean texImage2D(int target, int level, int internalFormat, int width, int height, int border,
        int format, int type, Buffer pixels, boolean useMipmap) {

    // NOTE: null pixels are allowed

    if (pixels != null && !(pixels instanceof ByteBuffer)) {
        throw new Error(
                "buffer should be a " + ByteBuffer.class.getName() + ", not a " + pixels.getClass().getName());
    }/*from w ww  .j a  v  a  2s  . co m*/
    ByteBuffer buf = (ByteBuffer) pixels;

    if (useMipmap) {
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
    }

    // if buf is not direct, copy it to a direct buffer
    if (buf != null && !buf.isDirect()) {
        imageBuf = updateBuffer(imageBuf, buf);
        buf = imageBuf;
    }

    clearGLErrors();

    GL11.glTexImage2D(translatePrismToGL(target), level, translatePrismToGL(internalFormat), width, height,
            border, translatePrismToGL(format), translatePrismToGL(type), buf);

    int glerror = getGLError();
    boolean hasError = glerror != GL11.GL_NO_ERROR;
    if (hasError) {
        System.err.println(String
                .format("WARNING: couldn't upload texture. glTexImage2D failed with code: 0x%x", glerror));
    }
    return !hasError;
}

From source file:illarion.graphics.lwjgl.TextureAtlasLWJGL.java

License:Open Source License

/**
 * Activate the texture and prepare it for usage by OpenGL.
 * //from   www  .  j  a v  a2s  . c om
 * @param resizeable true in case the texture shall be loaded with advanced
 *            rescaling methods, that are more calculation intensive but
 *            look better then the normal ones
 * @param allowCompression true if the texture is compressed at default
 *            settings, false if not. Best disallow compression for static
 *            images such as tiles, since the effects of the compression
 *            will be quite visible there
 */
@Override
@SuppressWarnings("nls")
public void activateTexture(final boolean resizeable, final boolean allowCompression) {

    if (!hasTextureData()) {
        throw new IllegalStateException("No texturedata loaded");
    }

    final int quality = Graphics.getInstance().getQuality();

    if (getTextureID() != 0) {
        removeTexture();
    }

    // generate new texture ID
    final int texID = getNewTextureID();
    setTextureID(texID);

    // bind texture ID
    DriverSettingsLWJGL.getInstance().enableTexture(texID);

    // prepare texture data
    if (resizeable) { // Textures will be resized -> smoothing would be good
        if (quality <= Graphics.QUALITY_LOW) {
            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);
        } else if ((quality <= Graphics.QUALITY_NORMAL) || isNoMipMaps()) {
            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);
        } else {
            if (GLContext.getCapabilities().OpenGL14) {
                GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
            } else {
                setNoMipMaps(true);
            }
            if (!isNoMipMaps()) {
                GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER,
                        GL11.GL_LINEAR_MIPMAP_LINEAR);
                GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
            } else {
                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);
            }
        }
    } else {
        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.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);

    if (GLContext.getCapabilities().OpenGL13) {
        GL11.glHint(GL13.GL_TEXTURE_COMPRESSION_HINT, GL11.GL_NICEST);
    }

    // setup texture compression
    final boolean activateCompression = GLContext.getCapabilities().OpenGL13
            && ((allowCompression && (quality < Graphics.QUALITY_MAX)) || (quality <= Graphics.QUALITY_LOW));
    if (isTextureRGBA()) {
        internalFormat = GL11.GL_RGBA;
        sourceFormat = GL11.GL_RGBA;
        if (activateCompression) {
            internalFormat = GL13.GL_COMPRESSED_RGBA;
        }
    } else if (isTextureRGB()) {
        internalFormat = GL11.GL_RGB;
        sourceFormat = GL11.GL_RGB;
        if (activateCompression) {
            internalFormat = GL13.GL_COMPRESSED_RGB;
        }
    } else if (isTextureGrey()) {
        internalFormat = GL11.GL_LUMINANCE;
        sourceFormat = GL11.GL_LUMINANCE;
        if (activateCompression) {
            internalFormat = GL13.GL_COMPRESSED_LUMINANCE;
        }
    } else if (isTextureGreyAlpha()) {
        internalFormat = GL11.GL_LUMINANCE_ALPHA;
        sourceFormat = GL11.GL_LUMINANCE_ALPHA;
        if (activateCompression) {
            internalFormat = GL13.GL_COMPRESSED_LUMINANCE_ALPHA;
        }
    }

    final ByteBuffer texData = getTextureData();

    final int texWidth = getTextureWidth();
    final int texHeight = getTextureHeight();

    // produce a texture from the byte buffer
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, internalFormat, texWidth, texHeight, 0, sourceFormat,
            GL11.GL_UNSIGNED_BYTE, texData);

    if (quality < Graphics.QUALITY_MAX) {
        texIDBuffer.rewind();
        GL11.glGetTexLevelParameter(GL11.GL_TEXTURE_2D, 0, GL13.GL_TEXTURE_COMPRESSED, texIDBuffer);

        texData.rewind();
        if (texIDBuffer.get(0) == GL11.GL_FALSE) {
            int newInternalFormat = internalFormat;
            if (internalFormat == GL13.GL_COMPRESSED_LUMINANCE_ALPHA) {
                newInternalFormat = GL13.GL_COMPRESSED_RGBA;
            } else if (internalFormat == GL13.GL_COMPRESSED_LUMINANCE) {
                newInternalFormat = GL13.GL_COMPRESSED_RGB;
            }
            final int orgSize = texData.remaining();
            if (newInternalFormat != internalFormat) {
                GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, newInternalFormat, texWidth, texHeight, 0,
                        sourceFormat, GL11.GL_UNSIGNED_BYTE, texData);
                GL11.glGetTexLevelParameter(GL11.GL_TEXTURE_2D, 0, GL13.GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
                        texIDBuffer);
                final int newSize = texIDBuffer.get(0);
                if (newSize > orgSize) {
                    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, internalFormat, texWidth, texHeight, 0,
                            sourceFormat, GL11.GL_UNSIGNED_BYTE, texData);
                }
            }
        }
    }

    texIDBuffer.rewind();
    GL11.glGetTexLevelParameter(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_INTERNAL_FORMAT, texIDBuffer);
    internalFormat = texIDBuffer.get();

    discardImageData();
}

From source file:ion2d.INTexture2D.java

License:Open Source License

/**
 * Can only generate mipmap with opengl 1.4 or greater
 *//*from w  w w  . j a  va 2  s .  co m*/
public void glGenerateMipMap() {
    this.bind();
    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
}

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  a  v a 2 s .  c  om*/
    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 .  jav a  2s. c o m*/

    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:org.getspout.spout.config.MipMapUtils.java

License:Open Source License

public static void initalizeTexture(int textureId) {
    GL11.glBindTexture(3553, textureId);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR);

    int textureWidth = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_WIDTH);
    int tileWidth = textureWidth / 16;

    setMipmapLevels(textureId, (int) Math.round(Math.log((double) tileWidth) / Math.log(2D)));

    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LOD, getMipmapLevels(textureId));

    ContextCapabilities capabilities = GLContext.getCapabilities();
    if (capabilities.OpenGL30) {
        MipMapUtils.mode = 1;/*w w w.  j a va  2s. co m*/
    } else if (capabilities.GL_EXT_framebuffer_object) {
        MipMapUtils.mode = 2;
    } else if (capabilities.OpenGL14) {
        MipMapUtils.mode = 3;
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
    }
}

From source file:org.lwjgl.demo.opengl.textures.BillboardCubemapDemo.java

License:Open Source License

void createTexture() throws IOException {
    int tex = glGenTextures();
    glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, tex);
    glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    ByteBuffer imageBuffer;/* w  w  w. j  a va  2s  .  c o  m*/
    IntBuffer w = BufferUtils.createIntBuffer(1);
    IntBuffer h = BufferUtils.createIntBuffer(1);
    IntBuffer comp = BufferUtils.createIntBuffer(1);
    String[] names = { "right", "left", "top", "bottom", "front", "back" };
    ByteBuffer image;
    if (caps.GL_EXT_texture_filter_anisotropic) {
        float maxAnisotropy = glGetFloat(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT);
        System.out.println("EXT_texture_filter_anisotropic available: Will use " + (int) maxAnisotropy
                + "x anisotropic filtering.");
        glTexParameterf(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy);
    } else {
        System.err
                .println("EXT_texture_filter_anisotropic unavailable: Distorted light might look too blurry.");
    }
    if (caps.OpenGL14) {
        System.out
                .println("OpenGL 1.4 available: Will use automatic mipmap generation via GL_GENERATE_MIPMAP.");
        glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
        glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL14.GL_GENERATE_MIPMAP, GL_TRUE);
    } else {
        System.err.println(
                "OpenGL 1.4 unavailable: Aliasing effects might be visible (texture looks too crisp).");
        glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    }
    for (int i = 0; i < 6; i++) {
        imageBuffer = ioResourceToByteBuffer("org/lwjgl/demo/space_" + names[i] + (i + 1) + ".jpg", 8 * 1024);
        if (!stbi_info_from_memory(imageBuffer, w, h, comp))
            throw new IOException("Failed to read image information: " + stbi_failure_reason());
        image = stbi_load_from_memory(imageBuffer, w, h, comp, 0);
        if (image == null)
            throw new IOException("Failed to load image: " + stbi_failure_reason());
        glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + i, 0, GL_RGB8, w.get(0), h.get(0), 0, GL_RGB,
                GL_UNSIGNED_BYTE, image);
        stbi_image_free(image);
    }
    if (caps.OpenGL32 || caps.GL_ARB_seamless_cube_map) {
        System.out.println("ARB_seamless_cube_map available: Will use seamless cubemap sampling.");
        glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
    } else {
        System.err.println("ARB_seamless_cube_map unavailable: Cubemap might have seams.");
    }
}

From source file:org.spoutcraft.client.config.MipMapUtils.java

License:Open Source License

public static void initalizeTexture(int textureId) {
    SpoutClient.getHandle().renderEngine.bindTexture(textureId);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR);

    int textureWidth = GL11.glGetTexLevelParameteri(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_WIDTH);
    int tileWidth = textureWidth / 16;

    setMipmapLevels(textureId, (int) Math.round(Math.log((double) tileWidth) / Math.log(2D)));

    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LOD, getMipmapLevels(textureId));

    ContextCapabilities capabilities = GLContext.getCapabilities();
    if (capabilities.OpenGL30) {
        MipMapUtils.mode = 1;/*from  w  w  w .  j  a va  2  s. c  o  m*/
    } else if (capabilities.GL_EXT_framebuffer_object) {
        MipMapUtils.mode = 2;
    } else if (capabilities.OpenGL14) {
        MipMapUtils.mode = 3;
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
    }
}

From source file:org.spoutcraft.client.gui.MCRenderDelegate.java

License:Open Source License

public void drawTexture(Texture textureBinding, int width, int height, Color color, boolean blend, int left,
        int top, boolean mipmap, int filter) {
    if (textureBinding == null) {
        return;//w  w  w.j  a v a2s  . c o m
    }
    GL11.glPushMatrix();
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    boolean wasBlend = GL11.glGetBoolean(GL11.GL_BLEND);
    if (blend) {
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(770, 771);
    }
    GL11.glDepthMask(false);
    bindColor(color);
    SpoutClient.getHandle().renderEngine.bindTexture(textureBinding.getTextureID());
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filter);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, filter);
    if (mipmap) {
        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, 8);

        ContextCapabilities capabilities = GLContext.getCapabilities();
        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.OpenGL14) {
            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
        }
    }

    double tLeft = 0, tTop = 0, rWidth = textureBinding.getWidth(), rHeight = textureBinding.getHeight(),
            tWidth = rWidth, tHeight = rHeight;
    if (top >= 0 && left >= 0) {
        tWidth = Math.min(tWidth,
                (width / (double) textureBinding.getImageWidth()) * textureBinding.getWidth());
        tHeight = Math.min(tHeight,
                (height / (double) textureBinding.getImageHeight()) * textureBinding.getHeight());
        tLeft = Math.min(
                Math.max(0, (left / (double) textureBinding.getImageWidth())) * textureBinding.getWidth(),
                rWidth);
        tTop = Math.min(
                Math.max(0, (top / (double) textureBinding.getImageHeight()) * textureBinding.getHeight()),
                rHeight);
    }
    tHeight = -tHeight;
    tTop = rHeight - tTop;

    Tessellator tessellator = Tessellator.instance;
    tessellator.startDrawingQuads();
    tessellator.addVertexWithUV(0.0D, height, -90, tLeft, tTop + tHeight); // draw corners
    tessellator.addVertexWithUV(width, height, -90, tLeft + tWidth, tTop + tHeight);
    tessellator.addVertexWithUV(width, 0.0D, -90, tLeft + tWidth, tTop);
    tessellator.addVertexWithUV(0.0D, 0.0D, -90, tLeft, tTop);

    tessellator.draw();
    GL11.glDepthMask(true);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    GL11.glPopMatrix();
    if (blend && !wasBlend) {
        GL11.glDisable(GL11.GL_BLEND);
    }
}