58
58
- (void) textureFromCgImage: (CGImageRef) img texName: (GLuint*) texname width: (size_t) width height: (size_t) height repeat: (BOOL) doRepeat mipmap: (BOOL) doMipmap filter: (BOOL) doFilter
60
60
void* spriteData = malloc(width * height * 4);
62
CGContextRef spriteContext = CGBitmapContextCreate(spriteData, width, height, 8, width * 4, CGImageGetColorSpace(img), kCGImageAlphaPremultipliedLast);
64
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
65
CGContextRef spriteContext = CGBitmapContextCreate(spriteData, width, height, 8, width * 4, colorSpace, kCGImageAlphaPremultipliedLast);
66
CGColorSpaceRelease(colorSpace);
63
68
CGContextDrawImage(spriteContext, CGRectMake(0.0, 0.0, (CGFloat)width, (CGFloat)height), img);
64
69
CGContextRelease(spriteContext);
80
85
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, doFilter ? GL_LINEAR : GL_NEAREST);
83
- (void) loadTextureNamed: (NSString*) name texName: (GLuint*) texname repeat: (BOOL) doRepeat mipmap: (BOOL) doMipmap filter: (BOOL) doFilter
88
- (void) loadTextureFromBitmapNamed: (NSString*) name texName: (GLuint*) texname repeat: (BOOL) doRepeat mipmap: (BOOL) doMipmap filter: (BOOL) doFilter
86
91
// Creates a Core Graphics image from an image file
102
static CGImageRef CreateCGImageFromPDFPage(CGPDFDocumentRef document, size_t pageNumber, int width, int height)
105
CGPDFPageRef page = CGPDFDocumentGetPage(document, pageNumber);
109
// CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
111
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
112
// void* data = malloc(4*width*height);
113
CGContextRef bitmapContext = CGBitmapContextCreate(NULL, width, height, 8, width * 4, colorSpace, kCGImageAlphaPremultipliedLast);
114
CGColorSpaceRelease(colorSpace);
122
CGAffineTransform M = CGPDFPageGetDrawingTransform(page, kCGPDFMediaBox, CGRectMake(0.0f, 0.0f, width, height), 0, NO);
124
CGContextConcatCTM(bitmapContext, M);
125
CGContextDrawPDFPage(bitmapContext, page);
126
CGImageRef pdfImage = CGBitmapContextCreateImage(bitmapContext);
127
CFRelease(bitmapContext);
133
static CGImageRef CreateImageFromPDFNamed(NSString* name, int width, int height)
135
CFURLRef url = CFURLCreateWithFileSystemPath(NULL, (CFStringRef) [[NSBundle mainBundle] pathForResource: name ofType: nil], 0, NO);
136
CGPDFDocumentRef pdfDoc = CGPDFDocumentCreateWithURL(url);
140
CGImageRef img = CreateCGImageFromPDFPage(pdfDoc, 1, width, height);
142
CGPDFDocumentRelease(pdfDoc);
148
- (void) loadTextureFromPDFNamed: (NSString*) name texName: (GLuint*) texname width: (size_t) width height: (size_t) height repeat: (BOOL) doRepeat mipmap: (BOOL) doMipmap filter: (BOOL) doFilter
151
CGImageRef img = CreateImageFromPDFNamed(name, width, height);
152
[self textureFromCgImage: img texName: texname width: width height: height repeat: doRepeat mipmap: doMipmap filter: doFilter];
98
157
//The GL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:
99
158
- (id)initWithCoder:(NSCoder*)coder {