I am new to working with image formats, so i was happy to successfully load and display a KTX image in my OpenGL application.
Howerver, i am not able to create KTX images that have transparency, here’s what i do:
I create a and save PNG images that have transparency (with gimp).
> identify image.png
> image.png PNG 256x256 256x256+0+0 8-bit sRGB 41.9KB 0.000u 0:00.000
I use ImageMagick’s ‘convert’ tool to create a PAM file:
> convert image.png PNG8:image.pam
> identify image.pam
> image.pam PNG 256x256 256x256+0+0 8-bit sRGB 4.96KB 0.000u 0:00.000
I call toktx to convert to KTX:
> toktx image image.pam
> toktx: “image.pam” is not a valid .pam, .pgm or .ppm file
Certainly i’m doing something wrong, so i searched the net for help, but there are so many formats and tools
that i got lost. Can you help me, please?
There is not enough information here to tell if the PNG has an alpha channel or not. You’ll need to use identify -verbose.
Are you sure you exported the alpha channel? I haven’t used gimp but the image tools I have used require you to make an explicit selection to export an alpha channel to a PNG.
This command is actually telling convert to output the image in PNG8 format even though the output file has the extension .pam. convert image.png image.pam should be sufficient. PNG8 is “8-bit indexed with optional binary transparency” and judging by the file size, which is considerably smaller than the input, 8-bit indexed is what you got. You need a full alpha channel for use with OpenGL* and toktx.
There is an OES_compressed_palletted texture extension for OpenGL ES 1.x but toktx does not support creating KTX files with this format as they are almost never used any more.
Thanks for explaining that. The reason i was calling convert this way is because in my first attempts on loading and displaying the converted KTX image i got black color instead of transparency and i was desperate. I tried again the way you described. Now ‘identify image.pam’ gives me the same output for alpha as for image.png, the file size is considerably bigger:
I wrote my own KTX loader and am using the values as i get them from the KTX header and also set the unpack alignment as stated in the format description.
Since calling glGetError never showed something, i thought i was doing that part correctly.
Sorry for my ignorance, the topic is quite overwhelming. Maybe you have a suggestion what i could try or what i should investigate/read to solve this.
After some time of testing different texture tools i finally found one that can convert PNG to KTX format exactly the way i wanted and expected: PVRTexTool.
I am very pleased to see that contrary to me assuming i messed up my code or image creation/saving, i did it right.
Still, i would like to know what the correct way of doing it with ImageMagick would be.
PVRTexTool is a utility for compressing textures, which is an important technique that ensures the lowest possible texture memory overhead at application run-time. The PVRTexTool package includes a library, command-line and GUI tools, and a set of plug-ins. Plug-ins are available for Autodesk 3ds Max, Autodesk Maya, and Adobe Photoshop.
Each component is capable of converting to a variety of popular compressed texture formats such as PVRTC and ETC, as well as all of the core texture formats for a variety of different APIs. They also include a number of advanced features to pre-process the image data, for example, border generation, colour bleeding and normal map generation.
Textures can be saved to DDS, KTX, or PVR (Imagination’s PowerVR Texture Container format which benefits from full public specification, support for custom metadata, as well as complete and optimized resource loading code in the PVRTools).