It seems like MTKTexureLoader newTextureWithContentsOfURL...
automatically flips the image. This causes all of my models and meshes containing conventional UV coordinates to display incorrectly. I didn't see anything in the options to specify whether this happens or not. Is there some way to use MTKTextureLoader and maintain the orientation of the image?
I don't see anyway to get MTKTextureLoader
to flip your image, but you can simply flip your texture coordinates:
{ u, v } -> { u, 1-v }
As of iOS 10, you can pass an option to the MTKTextureLoader
initializer. For example loading a texture from a CGImage:
let textureOut = try textureLoader.newTexture(with: cgImage,
options: [MTKTextureLoaderOptionOrigin: MTKTextureLoaderOriginTopLeft as NSObject])
will flip images that initially have their origin in the bottom left corner.
If you have to deal with iOS < 9, you can force your users to update use both approaches from Rythmic Fistman or Denn Nevera in the answers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With