Skip to content
jvm gli
Branch: master
Clone or download


Build Status license Release Awesome Kotlin Badge Slack Status

This is the Kotlin port of the original OpenGL Image (GLI), written by g-truc (repository), a header only C++ image library for graphics software.

GLI provides classes and functions to load image files, facilitate graphics APIs texture creation, compare textures, access texture texels, sample textures, convert textures, generate mipmaps, etc.

This library works perfectly with OpenGL or Vulkan but it also ensures interoperability with other third party libraries and SDK. It is a good candidate for software rendering (raytracing / rasterization), image processing, image based software testing or any development context that requires a simple and convenient image library.

Don't hesitate to contribute to the project by submitting issues or pull requests for bugs and features. Any feedback is welcome at


import gli_.gli

fun createTexture(filename: String): Int {

    val texture = gli.load(filename)
        return 0 = gl.Profile.GL33
    val format =, texture.swizzles)
    val target =
    assert(texture.format.isCompressed && target == gl.Target._2D)

    val textureName = intBufferBig(1)
    glBindTexture(target.i, textureName[0])
    glTexParameteri(target.i, GL_TEXTURE_BASE_LEVEL, 0)
    glTexParameteri(target.i, GL_TEXTURE_MAX_LEVEL, texture.levels() - 1)
    val swizzles = intBufferBig(4)
    format.swizzles to swizzles
    glTexParameteriv(target.i, GL_TEXTURE_SWIZZLE_RGBA, swizzles)
    var extent = texture.extent()
    glTexStorage2D(target.i, texture.levels(), format.internal.i, extent.x, extent.y)
    for(level in 0 until texture.levels()) {
        extent = texture.extent(level)
                target.i, level, 0, 0, extent.x, extent.y,
                format.internal.i,, 0, level))
    val texName = textureName[0]
    return texName

Kotlin with gl-next:

    fun createTexture(filename: String): Int {

        val texture = gli.load(filename)
            return 0 = gl.Profile.GL33
        val (target, format) =
        assert(texture.format.isCompressed && target == gl.Target._2D)

        return initTexture2d {
            levels = 0 until texture.levels()
            swizzles = format.swizzles
            storage(texture.levels(), format.internal, texture.extent())
            levels.forEach {
                compressedSubImage(it, texture.extent(it), format.internal,, 0, it))


public static int createTexture(String filename) {

    Texture texture = gli.load(filename);
    if (texture.empty())
        return 0;;
    gl.Format format =, texture.getSwizzles());
    gl.Target target =;
    assert (texture.getFormat().isCompressed() && target == gl.Target._2D);

    IntBuffer textureName = intBufferBig(1);
    glBindTexture(target.getI(), textureName.get(0));
    glTexParameteri(target.getI(), GL12.GL_TEXTURE_BASE_LEVEL, 0);
    glTexParameteri(target.getI(), GL12.GL_TEXTURE_MAX_LEVEL, texture.levels() - 1);
    IntBuffer swizzles = intBufferBig(4);
    glTexParameteriv(target.getI(), GL33.GL_TEXTURE_SWIZZLE_RGBA, swizzles);
    Vec3i extent = texture.extent(0);
    glTexStorage2D(target.getI(), texture.levels(), format.getInternal().getI(), extent.x, extent.y);
    for (int level = 0; level < texture.levels(); level++) {
        extent = texture.extent(level);
            target.getI(), level, 0, 0, extent.x, extent.y,
            format.getInternal().getI(),, 0, level));
    int texName = textureName.get(0);
    return texName

Supported Image Formats

  • KTX
  • DDS
  • KMG
  • jpg
  • png
  • gif
  • bmp
  • tga
You can’t perform that action at this time.