Note that there are some explanatory texts on larger screens.

plurals
  1. POCrop a UIImage to use with GLKTextureLoader
    primarykey
    data
    text
    <p>I am trying to crop an area out of a UIImage to use with GLKTextureLoader. I can set the texture directly using the the UIImage with the following:</p> <pre><code>- (void)setTextureImage:(UIImage *)image { NSError *error; texture = [GLKTextureLoader textureWithCGImage:image.CGImage options:nil error:&amp;error]; if(error) { NSLog(@"Texture Error:%@", error); } else { self.textureCoordinates[0] = GLKVector2Make(1.0f, 1.0f); self.textureCoordinates[1] = GLKVector2Make(1.0f, 0); self.textureCoordinates[2] = GLKVector2Make(0, 0); self.textureCoordinates[3] = GLKVector2Make(0, 1.0f); } } </code></pre> <p>However, if I try crop the image this way:</p> <pre><code>- (void)setTextureImage:(UIImage *)image { NSError *error; CGImageRef imageRef = CGImageCreateWithImageInRect(image.CGImage, CGRectMake(0.0, 64.0f, 64.0f, 64.0f)); texture = [GLKTextureLoader textureWithCGImage:imageRef options:nil error:&amp;error]; if(error) { NSLog(@"[SF] Texture Error:%@", error); } else { self.textureCoordinates[0] = GLKVector2Make(1.0f, 1.0f); self.textureCoordinates[1] = GLKVector2Make(1.0f, 0); self.textureCoordinates[2] = GLKVector2Make(0, 0); self.textureCoordinates[3] = GLKVector2Make(0, 1.0f); } } </code></pre> <p>I get this error:</p> <pre><code>Texture Error:Error Domain=GLKTextureLoaderErrorDomain Code=12 "The operation couldn’t be completed. (GLKTextureLoaderErrorDomain error 12.)" UserInfo=0x6a6b550 {GLKTextureLoaderErrorKey=Image decoding failed} </code></pre> <p>How can I take a section of the UIImage to use as a texture with GLKTextureLoader?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload