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 one of the compressed formats, e.g. ETC1, supported by OpenGL family APIs and extensions or can be stored uncompressed.
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.
Compatibilitylibktx is written using only Posix functions and is very portable. The current version includes both a GNU make file and a Visual Studio 2008 project file for building it.
Features- Instantiate an OpenGL texture from a KTX file
- Decompress an ETC1 compressed texture image when the hardware does not have ETC1 support.
- Construct a hash table of key-value pairs from the KTX file as the texture is loaded
- Write a KTX file from an array of source images and an optional hash table of key-value pairs.
- Construct and populate a hash table of key-value pairs.
- See the full documentation.
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 compressed textures has a separate license that restricts it to uses associated
with Khronos Group APIs. See the full license
text for more details.
Creating KTX Files
Currently two tools are available for creating KTX files:
- etcpack creates RGB textures compressed using ETC1 (Ericsson Texture Compression 1)
- toktx creates uncompressed ALPHA, LUMINANCE, LUMINANCE_ALPHA, RGB or RGBA textures
Both tools 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's ETC Developer Home Page to download etcpack where you will be asked to agree to their click-through license.
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.
Downloads
- Download the libktx and toktx source code. The bundle includes OpenGL ES applications showing how to use the library to load textures.
- Download the Windows XP 32-bit binary of toktx.
Packages last updated 1/26/2012.
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.
Subversion Repository
The subversion repository for libktx and toktx can be accessed, read-only, at
https://cvs.khronos.org/svn/repos/ogles/trunk/src/public/KTX/
There will soon be a registration mechanism for those who wish to become contributors to the KTX project. Contributors will be granted write access.
Copyright © 2010 Khronos Group. All rights reserved.

