Loading PNG’s on IOS Simulator V’s on the device.
My company developer profile came through today and I decided to run my tech demo’s on an actual device instead of in the simulator. Immediately it was evident that something was wrong when all the PNG’s failed to load. I am using lodepng, a lightweight C++ PNG library, for my image loading. This library works perfectly on windows, OSX, Linux and on IOS when running in the simulator and after quickly ruling out and endian issue, I thought that Apple must be doing something to my image. An interesting Google journey later I have found that:
XCode will convert PNG images so that the header chunk is CgBI (instead of IHDR), and that confuses 3rd party libs like lodepng, since a character in Apple’s header indicates that the data is in a private format. This operation only takes place for the target device – the simulator is unaffected. There are 4 ways to work around the issue (from easiest to hardest).
1) Rename your images to something else (eg. .ppng), and the XCode packaging tool will ignore your file.
2) According to the following link (http://www.imgtec.com/powervr/insider/sdk/KhronosOpenGLES1xMBX.asp), you need to add the following build settings defintion for each target. IPHONEOPTIMIZEOPTIONS=-skip-PNGs
3) Teach your PNG decoder to handle Apple’s CgBI format.
4) Use the Cocoa UIImage classes or the Texture2D.m class.
Options 3 and 4 are immediately discarded. 3 because I do not want to have to write and maintain a custom PNG loader for IOS and 4 because the game must be written in C++ and remain platform independent. For now option 1 is quick and easy. Thankfully OSX does not rely on extensions to open files and can still display .ppng in preview etc…