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.
Compatibilitylibktx 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- Instantiate an OpenGL texture from a KTX file
- Decompress an ETC1, ETC2 or EAC compressed texture image if the context does not support the format.
- Convert textures with legacy LUMINANCE, LUMINANCE_ALPHA, etc. formats to the equivalent RED, RG, etc. format and appropriate swizzle, if loading in an OpenGL Core Profile context.
- 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, 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.
Creating KTX Files
Currently three tools are available for creating KTX files:
- etcpack creates files with textures compressed by any of the ETC1, ETC2 or EAC formats.
- toktx creates files with uncompressed textures in RED, RG, RGB or RGBA sized or unsized formats. Options are available to use ALPHA, LUMINANCE and LUMINANCE_ALPHA instead of RED and RG. This is a change in version 1.1. Previously ALPHA and LUMINANCE_ALPHA were the defaults for 1 and 2 channel images.
- PVRTexTool from Imagination Technology is graphical tool that can create files with either compressed or uncompressed 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 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.
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 1.0 & 3.0 and OpenGL 3.3 applications showing how to use the library to load textures. It
- Download the Windows XP 32-bit binary of toktx.
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.
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 © 2013 Khronos Group. All rights reserved.

