RSS

(root)/iphone/common : 23 : common/source/GLESView.m

To get this branch, use:
bzr branch /browse/iphone/common

« back to all changes in this revision

Viewing changes to common/source/GLESView.m

Dömötör Gulyás
2009-08-09 18:33:08
Revision ID: dognotdog@gmail.com-20090809163308-k92rpn48plb13cqe
adds ability to create textures from PDF; adds color value to shaders; jigs now displays movement mode

Show diffs side-by-side

added added

removed removed

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
59
59
{
60
60
        void* spriteData = malloc(width * height * 4);
61
 
 
62
 
        CGContextRef spriteContext = CGBitmapContextCreate(spriteData, width, height, 8, width * 4, CGImageGetColorSpace(img), kCGImageAlphaPremultipliedLast);
 
61
        
 
62
        assert(img);
 
63
 
 
64
        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
 
65
        CGContextRef spriteContext = CGBitmapContextCreate(spriteData, width, height, 8, width * 4, colorSpace, kCGImageAlphaPremultipliedLast);
 
66
        CGColorSpaceRelease(colorSpace);
 
67
 
63
68
        CGContextDrawImage(spriteContext, CGRectMake(0.0, 0.0, (CGFloat)width, (CGFloat)height), img);
64
69
        CGContextRelease(spriteContext);
65
70
        
80
85
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, doFilter ? GL_LINEAR : GL_NEAREST);
81
86
}
82
87
 
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
84
89
{
85
90
 
86
91
        // Creates a Core Graphics image from an image file
94
99
        
95
100
}
96
101
 
 
102
static CGImageRef       CreateCGImageFromPDFPage(CGPDFDocumentRef document, size_t pageNumber, int width, int height)
 
103
{
 
104
 
 
105
        CGPDFPageRef page = CGPDFDocumentGetPage(document, pageNumber);
 
106
        if(!page)
 
107
                return NULL;
 
108
 
 
109
//      CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
 
110
 
 
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);
 
115
 
 
116
        if(!bitmapContext)
 
117
        {
 
118
                //free(data);
 
119
                return NULL;
 
120
        }
 
121
 
 
122
        CGAffineTransform M = CGPDFPageGetDrawingTransform(page, kCGPDFMediaBox, CGRectMake(0.0f, 0.0f, width, height), 0, NO);
 
123
        
 
124
        CGContextConcatCTM(bitmapContext, M);
 
125
        CGContextDrawPDFPage(bitmapContext, page);                                                                      
 
126
        CGImageRef pdfImage = CGBitmapContextCreateImage(bitmapContext);
 
127
        CFRelease(bitmapContext);
 
128
        //free(data);
 
129
        return pdfImage;  
 
130
 
 
131
 
132
 
 
133
static CGImageRef CreateImageFromPDFNamed(NSString* name, int width, int height)
 
134
{
 
135
        CFURLRef url = CFURLCreateWithFileSystemPath(NULL, (CFStringRef) [[NSBundle mainBundle] pathForResource: name ofType: nil], 0, NO);
 
136
        CGPDFDocumentRef pdfDoc = CGPDFDocumentCreateWithURL(url);
 
137
        CFRelease(url);
 
138
        assert(pdfDoc);
 
139
        
 
140
        CGImageRef img = CreateCGImageFromPDFPage(pdfDoc, 1, width, height);
 
141
        
 
142
        CGPDFDocumentRelease(pdfDoc);
 
143
        
 
144
        return img;
 
145
}
 
146
 
 
147
 
 
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
 
149
{
 
150
 
 
151
        CGImageRef img = CreateImageFromPDFNamed(name, width, height);
 
152
        [self textureFromCgImage: img texName: texname width: width height: height repeat: doRepeat mipmap: doMipmap filter: doFilter];
 
153
        CGImageRelease(img);
 
154
}
 
155
 
97
156
 
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 {

Loggerhead 1.17 is a web-based interface for Bazaar branches