Skip to content

Commit

Permalink
Added an OpenGL ES texture output class, and a sample application to …
Browse files Browse the repository at this point in the history
…show this off.
  • Loading branch information
BradLarson committed Mar 6, 2012
1 parent cb23fa0 commit e77fc9d
Show file tree
Hide file tree
Showing 22 changed files with 1,615 additions and 18 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ For example, an application that takes in live video from the camera, converts t

- **GPUImageScreenBlendFilter**: Applies a screen blend of two images

- **GPUImageExclusionBlendFilter**: Applies an exclusion blend of two images

- **GPUImageDifferenceBlendFilter**: Applies a difference blend of two images

- **GPUImageHardLightBlendFilter**: Applies a hard light blend of two images

- **GPUImageSoftLightBlendFilter**: Applies a soft light blend of two images

### Visual effects ###

- **GPUImagePixellateFilter**: Applies a pixellation effect on an image or video
Expand Down
14 changes: 14 additions & 0 deletions examples/CubeExample/Classes/CubeExampleAppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#import <UIKit/UIKit.h>

@class EAGLView;

@interface CubeExampleAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
EAGLView *glView;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet EAGLView *glView;

@end

34 changes: 34 additions & 0 deletions examples/CubeExample/Classes/CubeExampleAppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#import "CubeExampleAppDelegate.h"
#import "EAGLView.h"

@implementation CubeExampleAppDelegate

@synthesize window;
@synthesize glView;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
}

- (void)applicationWillTerminate:(UIApplication *)application
{
}

- (void)dealloc
{
[window release];
[glView release];

[super dealloc];
}

@end
16 changes: 16 additions & 0 deletions examples/CubeExample/Classes/EAGLView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>

#import "ESRenderer.h"

@interface EAGLView : UIView
{
CGPoint lastMovementPosition;
@private
id <ESRenderer> renderer;

}

- (void)drawView:(id)sender;

@end
92 changes: 92 additions & 0 deletions examples/CubeExample/Classes/EAGLView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#import "EAGLView.h"

#import "ES2Renderer.h"

@implementation EAGLView

// You must implement this method
+ (Class)layerClass
{
return [CAEAGLLayer class];
}

//The EAGL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:
- (id)initWithCoder:(NSCoder*)coder
{
if ((self = [super initWithCoder:coder]))
{
// Set scaling to account for Retina display
if ([self respondsToSelector:@selector(setContentScaleFactor:)])
{
self.contentScaleFactor = [[UIScreen mainScreen] scale];
}

// Get the layer
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;

eaglLayer.opaque = TRUE;
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];

renderer = [[ES2Renderer alloc] init];
}

return self;
}

- (void)dealloc
{
[renderer release];

[super dealloc];
}

#pragma mark -
#pragma mark UIView layout methods

- (void)drawView:(id)sender
{
[renderer renderByRotatingAroundX:0 rotatingAroundY:0];
}

- (void)layoutSubviews
{
NSLog(@"Scale factor: %f", self.contentScaleFactor);
[renderer resizeFromLayer:(CAEAGLLayer*)self.layer];
[self drawView:nil];
}

#pragma mark -
#pragma mark Touch-handling methods

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSMutableSet *currentTouches = [[[event touchesForView:self] mutableCopy] autorelease];
[currentTouches minusSet:touches];

// New touches are not yet included in the current touches for the view
lastMovementPosition = [[touches anyObject] locationInView:self];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
{
CGPoint currentMovementPosition = [[touches anyObject] locationInView:self];
[renderer renderByRotatingAroundX:(lastMovementPosition.x - currentMovementPosition.x) rotatingAroundY:(lastMovementPosition.y - currentMovementPosition.y)];
lastMovementPosition = currentMovementPosition;
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSMutableSet *remainingTouches = [[[event touchesForView:self] mutableCopy] autorelease];
[remainingTouches minusSet:touches];

lastMovementPosition = [[remainingTouches anyObject] locationInView:self];
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
// Handle touches canceled the same as as a touches ended event
[self touchesEnded:touches withEvent:event];
}

@end
39 changes: 39 additions & 0 deletions examples/CubeExample/Classes/ES2Renderer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#import "ESRenderer.h"

#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
#import <QuartzCore/QuartzCore.h>
#import "GPUImage.h"

@class PVRTexture;

@interface ES2Renderer : NSObject <ESRenderer, GPUImageTextureOutputDelegate>
{
@private
EAGLContext *context;

GLuint textureForCubeFace;

// The pixel dimensions of the CAEAGLLayer
GLint backingWidth;
GLint backingHeight;

// The OpenGL ES names for the framebuffer and renderbuffer used to render to this view
GLuint defaultFramebuffer, colorRenderbuffer, depthBuffer, msaaFramebuffer, msaaRenderbuffer, msaaDepthbuffer;

CATransform3D currentCalculatedMatrix;

GLuint program;

GPUImageVideoCamera *videoCamera;
GPUImageFilter *inputFilter, *outputFilter;
GPUImageTextureOutput *textureOutput;

}

- (void)renderByRotatingAroundX:(float)xRotation rotatingAroundY:(float)yRotation;
- (BOOL)resizeFromLayer:(CAEAGLLayer *)layer;
- (void)convert3DTransform:(CATransform3D *)transform3D toMatrix:(GLfloat *)matrix;

@end

Loading

0 comments on commit e77fc9d

Please sign in to comment.