Skip to content

Instantly share code, notes, and snippets.

@richcollins
Created August 9, 2009 08:23
Show Gist options
  • Save richcollins/164662 to your computer and use it in GitHub Desktop.
Save richcollins/164662 to your computer and use it in GitHub Desktop.
- (void)setupTexture
{
CGDataProviderRef provider = CGDataProviderCreateWithFilename([imagePath UTF8String]);
CGImageRef image = CGImageCreateWithPNGDataProvider(provider, NULL, true, kCGRenderingIntentDefault);
CGDataProviderRelease(provider);
size_t width = CGImageGetWidth(image);
size_t height = CGImageGetHeight(image);
realloc(textureData, width * height * 4);
CGContextRef textureContext = CGBitmapContextCreate(textureData, width, height, 8, width * 4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast);
CGContextDrawImage(textureContext, CGRectMake(0, 0, width, height), image);
CGImageRelease(image);
CGContextRelease(textureContext);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment