-
Notifications
You must be signed in to change notification settings - Fork 235
Home
Important
|
Under construction. Please ignore. Seems no way to make private until its ready. |
KTX (Khronos Texture) is a lightweight file format for OpenGL® and Vulkan® textures. 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 a cubemap array texture with mipmaps. Texture payloads can be in Basis Universal or UASTC formats, which can be transcoded to any GPU-supported format, in any of the block-compressed formats supported by OpenGL family and Vulkan APIs and extensions or in an uncompressed format. Basis Universal is a supercompressed block-compressed format. Other formats can be supercompressed with Zstandard.
The original file format specification was created by Khronos’s OpenGL ES and ARB-OpenGL ES Convergence Working Groups. The Version 2.0 file format specification was created by the 3D Formats Working Group which is also responsible for glTF™️.
The software in this repo includes libktx
, a library for reading and writing KTX files, .wasm
modules for libktx and a Basis transcoder together with Javascript wrappers and a set of tools. See the repo (../../README.md)[README.md]
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
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.
Usage examples
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. Working with KTX Files
Currently four tools are known to be 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. The Adreno texture tool from Qualcomm is a GUI tool for compression and visualization of textures. Mali Texture Compression Tool from ARM is a GUI tool that can create and view files with either compressed or uncompressed textures. PVRTexTool from Imagination Technology is graphical tool that can create and view files with either compressed or uncompressed textures.
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.
etcpack is available from its GitHub repository.
The Adreno texture tool is included in the Adreno SDK which can be downloaded from the Adreno GPU Tools and Resources page.
PVRTexTool is one of the PowerVR Tools. Download the PowerVR Tools Installer, run it and select the tools you wish to download and install.
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
The downloads below are very outdated. Clone the GitHub repository to get the latest source and to build binaries. Project files are available for all major platforms except Android.
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 zip format compressed tar format Download the Windows XP 32-bit binary of toktx. toktx.exe
Packages last updated 5/23/2013. Reporting Problems
To report problems or suggest new functionality, please use the issues list in the GitHub repository. Discussion and Questions
Use the KTX forum of the khronos.org forums for discussion and questions.