Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the options of MTKTextureLoader newTextureWithContentsOfURL?

I am trying to use MetalKit newTextureWithContentsOfURL to create the texture for a cow.

MTKTextureLoader *texture_loader = [[MTKTextureLoader alloc] initWithDevice:device];
NSURL *cow_image = [[NSBundle mainBundle] URLForResource:@"spot_texture" withExtension:@"png"];
NSError *error;
diffuse_texture = [texture_loader newTextureWithContentsOfURL:cow_image options:nil error:&error];

Here is the sample cow (top) and my cow (bottom) look.

Sample cow

My cow

I don't know the reason about this, but I think the options may help.

How to set this option using NSDictionary?

like image 609
BigFatTom Avatar asked Dec 07 '25 05:12

BigFatTom


1 Answers

Based on this Objective-C Literals

MTKTextureLoader *texture_loader = [[MTKTextureLoader alloc] initWithDevice:device];
NSURL *cow_image = [[NSBundle mainBundle] URLForResource:@"spot_texture" 
withExtension:@"png"];
NSError *error;
diffuse_texture = [texture_loader newTextureWithContentsOfURL:cow_image options:@{ MTKTextureLoaderOptionSRGB : @true, MTKTextureLoaderOptionOrigin : @true} 
error:&error];
like image 70
Hamid Yusifli Avatar answered Dec 08 '25 18:12

Hamid Yusifli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!