iosopengl-esglkitimagenamedglktextureloader

Issue using GLKTextureLoader and imageNamed: when loading same image multiple times


I get strange behaviour when I use the following code to load an image multiple times:

NSDictionary *options = @{GLKTextureLoaderOriginBottomLeft: @YES};
textureInfo = [GLKTextureLoader textureWithCGImage:[UIImage imageNamed:@"name"].CGImage 
                                           options:options
                                             error:nil];

It works as expected when I run load the image the first time, but when I try to load the same image again it's drawn upside down.

I think this has to do with the fact that it's actually the same CGImage that gets passed to the texture loader because of the use of imageNamed:. The flip transformation is therefore applied a second time on the same image.

Is there a way to get around this issue?


Solution

  • I guess you could flip the image, and load it the first time when your program starts.

    Or not use imageNamed. Or keep the texture in memory so you only have to load it once.