Reputation: 174
I'm making an iPhone application with OpenGL ES 2.0 using the GLKit. I'm using GLKTextureLoader to load textures. When my texture sits inside a mainBundle - EVERYTHING IS FINE. I get its name with command [[NSBundle mainBundle] pathForResource:@"brushRose.png" ofType:nil]
and the texture has a following path:
/var/mobile/Containers/Bundle/Application/D79492CB-D03C-464D-B06E-00D0DE4389DF/Texture Test.app/brushRose.png
When I try to download an absolutely same texture from Internet and store it inside Application's Documents
folder. Path is like follow:
/var/mobile/Containers/Data/Application/CD3FBAAB-B8AE-47F5-9C6E-51C854FC1620/Documents/brushes/ps_roses.png
I get a TERRIBLE END RESULT which can be observed on the picture below: First row - texture from mainBundle, second row - from Documents
Any ideas how to fix the second case are welcome.
Test project can be found here
Upvotes: 1
Views: 252
Reputation: 36084
When you build an app containing PNGs, Xcode runs pngcrush
on them which, among other things, pre-multiplies the alpha.
The "non main-Bundle" files you are using do not have pre-multiplied alpha. This explains the difference in appearance.
Your options are to run pngcrush
on your url textures, or stop pngcrush running in your project, or conditionally apply the GLKTextureLoaderApplyPremultiplication
when you load non-crushed PNGs:
NSMutableDictionary *options = [@{ GLKTextureLoaderOriginBottomLeft : @NO} mutableCopy];
if ( /** png is uncrushed **/ ) {
options[GLKTextureLoaderApplyPremultiplication] = @YES;
}
NSError* error;
GLKTextureInfo* texture = [GLKTextureLoader textureWithContentsOfFile:brushPath options:options error:&error];
Upvotes: 2