Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load an image using MTKTextureLoader without flipping?

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?

like image 915
Curyous Avatar asked Nov 15 '15 07:11

Curyous


Video Answer


2 Answers

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 }
like image 69
Rhythmic Fistman Avatar answered Oct 06 '22 12:10

Rhythmic Fistman


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.

like image 37
Bernardo Santana Avatar answered Oct 06 '22 12:10

Bernardo Santana