Created
July 27, 2013 12:14
-
-
Save rsaunders100/6094708 to your computer and use it in GitHub Desktop.
Core image rendering on a EAGLContext
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doesn't work. No errors; just a blank screen. In Interface Builder, I created a GLKViewController with a GLKView (did not create a subview; just using the one that comes with the view controller). Here's the code: