The KTX File Format and Tools

KTX (Khronos Texture) is a lightweight file format for OpenGL® textures, designed around how textures are loaded in OpenGL. KTX files contain all the parameters needed for texture loading. A single file can contain anything from a simple base-level 2D texture through to an array texture with all mipmap levels. Textures can be stored in any of the compressed formats supported by OpenGL family APIs and extensions or can be stored uncompressed. The latest versions of OpenGL and OpenGL ES include support for ETC2 and EAC compressed textures as a standard feature.

Format Specification

The file format specification was created by Khronos's OpenGL ES and ARB-OpenGL ES Convergence Working Groups and is applicable to both OpenGL and OpenGL ES.

libktx

libktx is an open source C library providing a set of functions for writing KTX files and for loading textures from them.

Compatibility

libktx is written using only Posix functions and is very portable. It includes both a GNU make file and a Visual Studio 2008 project file for building it.

Features of v2.0 Usage examples

The following example shows how to instantiate a texture using the library.

#define TEXTURE_FILE "../../../test images/up-reference.ktx"

    GLuint texture = 0;
    GLenum target;
    GLenum glerror;
    GLboolean isMipmapped;
    KTX_error_code ktxerror;

    ktxerror = ktxLoadTextureN(TEXTURE_FILE, &texture, &target, NULL, &isMipmapped, &glerror,
    	                       0, NULL);

    if (KTX_SUCCESS == ktxerror) {
        glEnable(target);

        if (isMipmapped) 
            /* Enable bilinear mipmapping */
            glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
        else
            glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    }

 

License

Most of the code is licensed under a modified BSD license. The code for unpacking ETC1, ETC2 and EAC compressed textures has a separate license that restricts it to uses associated with Khronos Group APIs. See the full license text for more details.

Working with KTX Files

Currently four tools are known to be available for creating KTX files:

Both etcpack & toktx use Netpbm, (.ppm, .pgm and .pam) files as source images. You can use freely available tools such as ImageMagick or XnView to convert most image formats to Netpbm formats.

You need to visit Ericsson Lab's Media Coding Page to download etcpack where you will be asked to agree to their click-through license.

You need to visit Imagination's PowerVR Insider pages and register in order to download PVRTexTool.

You can download the Mali Texture Compression Tool from the Mali Developer Center.

The source code for toktx is bundled with the libktx source, on which it is dependent, in the package available for download below. You can also download a Windows binary. Type toktx --help for usage.

You can use Pico Pixel for viewing KTX files & more and for debugging image handling in your applications.

Downloads

Packages last updated 5/23/2013.

Reporting Problems

To report problems or suggest new functionality, please use the Khronos Bugzilla with product "KTX" and component "library" or "toktx" as appropriate.

Discussion and Questions

Use the KTX forum of the khronos.org message boards for discussion and questions.

GitHub Repository

The source repository for libktx and toktx is on GitHub and can be accessed at

https://github.com/KhronosGroup/KTX

Copyright © 2013 Khronos Group. All rights reserved.