Core image rendering on a EAGLContext
// View controller is a subclass of GLKViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.eaglContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
self.ciContext = [CIContext
contextWithEAGLContext:self.eaglContext
options: @{kCIContextWorkingColorSpace:[NSNull null]} ];
GLKView *view = (GLKView *)self.view;
view.context = self.eaglContext;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
[EAGLContext setCurrentContext:self.eaglContext];
}
- (void) viewDidAppear:(BOOL)animated
{
[self updateScreen];
}
- (void) updateScreen
{
NSURL * testImageURL = [[NSBundle mainBundle] URLForResource:@"Image" withExtension:@"png"];
NSAssert(nil != testImageURL, @"Image not found");
CIImage * image = [CIImage imageWithContentsOfURL:testImageURL
options:@{ kCIImageColorSpace:[NSNull null] }];
CIFilter * filter = [CIFilter filterWithName:@"CISepiaTone"];
[filter setValue:image forKey:kCIInputImageKey];
[filter setValue:@0.8 forKey:@"InputIntensity"];
CIImage * result = [filter valueForKey:kCIOutputImageKey];
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
[self.ciContext drawImage:result inRect:[[UIScreen mainScreen] applicationFrame]
fromRect:[result extent]];
GLuint render_buffer = 0;
glBindRenderbuffer(GL_RENDERBUFFER, render_buffer);
[self.eaglContext presentRenderbuffer:GL_RENDERBUFFER];
}