Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed tabs to spaces, nicer to view code at github

  • Loading branch information...
commit 2636692e9ffaa9ba6d222dc29910f01c260cd608 1 parent 76343e0
Edward Patel authored
View
2  DemoProject/Classes/MainView.h
@@ -9,7 +9,7 @@
#import <UIKit/UIKit.h>
@interface MainView : UIView {
-
+
}
@end
View
70 DemoProject/Classes/MainViewController.m
@@ -41,42 +41,42 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller {
- [self dismissModalViewControllerAnimated:YES];
+ [self dismissModalViewControllerAnimated:YES];
}
- (IBAction)showInfo {
-
- FlipsideViewController *controller = [[FlipsideViewController alloc]
- initWithNibName:@"FlipsideView"
- bundle:nil];
- controller.delegate = self;
-
- DemoTransition *transition = [[[DemoTransition alloc] init] autorelease];
-
- EPGLTransitionView *glview = [[[EPGLTransitionView alloc]
- initWithView:self.view
- delegate:transition] autorelease];
-
+
+ FlipsideViewController *controller = [[FlipsideViewController alloc]
+ initWithNibName:@"FlipsideView"
+ bundle:nil];
+ controller.delegate = self;
+
+ DemoTransition *transition = [[[DemoTransition alloc] init] autorelease];
+
+ EPGLTransitionView *glview = [[[EPGLTransitionView alloc]
+ initWithView:self.view
+ delegate:transition] autorelease];
+
#ifdef ENABLE_PHASE_IN
-
- // Get texture for the "next" view
- [glview prepareTextureTo:controller.view];
-
- // If you are using an "IN" animation for the "next" view set appropriate
- // clear color (ie no alpha)
- [glview setClearColorRed:0.3
- green:0.3
- blue:0.3
- alpha:1.0];
+
+ // Get texture for the "next" view
+ [glview prepareTextureTo:controller.view];
+
+ // If you are using an "IN" animation for the "next" view set appropriate
+ // clear color (ie no alpha)
+ [glview setClearColorRed:0.3
+ green:0.3
+ blue:0.3
+ alpha:1.0];
#endif
-
- [glview startTransition];
-
- [self presentModalViewController:controller animated:NO];
-
-
- [controller release];
+
+ [glview startTransition];
+
+ [self presentModalViewController:controller animated:NO];
+
+
+ [controller release];
}
@@ -90,15 +90,15 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
*/
- (void)didReceiveMemoryWarning {
- // Releases the view if it doesn't have a superview.
+ // Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
-
- // Release any cached data, images, etc that aren't in use.
+
+ // Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
- // Release any retained subviews of the main view.
- // e.g. self.myOutlet = nil;
+ // Release any retained subviews of the main view.
+ // e.g. self.myOutlet = nil;
}
View
12 src/DemoTransition.h
@@ -33,13 +33,13 @@
// #define ENABLE_PHASE_IN
@interface DemoTransition : NSObject<EPGLTransitionViewDelegate> {
- // 4x6 part, 4 vertex 2 coords
- GLfloat vertices[4][6][4][2];
- GLfloat texcoords[4][6][4][2];
- float yOut[4][6];
- float dyOut[4][6];
+ // 4x6 part, 4 vertex 2 coords
+ GLfloat vertices[4][6][4][2];
+ GLfloat texcoords[4][6][4][2];
+ float yOut[4][6];
+ float dyOut[4][6];
#ifdef ENABLE_PHASE_IN
- float yIn[4][6];
+ float yIn[4][6];
#endif
}
View
216 src/DemoTransition.m
@@ -28,134 +28,134 @@ @implementation DemoTransition
- (void)setupTransition
{
- srand(time(NULL));
-
- // Setup matrices
+ srand(time(NULL));
+
+ // Setup matrices
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glOrthof(-1, 1, -1.5, 1.5, -10, 10); // Could also use glFrustum here for a 3D look
+ glOrthof(-1, 1, -1.5, 1.5, -10, 10); // Could also use glFrustum here for a 3D look
glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
- // Setup vertex data
- int i, j;
- const float kdx = 2.0/4.0;
- const float kdy = 3.0/6.0; // yes, they are same because parts are square, but here for completeness
- for (i=0; i<4; i++) {
- for (j=0; j<6; j++) {
- float vx = -1.0+kdx*i;
- float vy = -1.5+kdy*j;
- float tx = i/4.0;
- float ty = (5-j)/6.0;
- vertices[i][j][0][0] = vx;
- vertices[i][j][0][1] = vy;
- vertices[i][j][1][0] = vx+kdx;
- vertices[i][j][1][1] = vy;
- vertices[i][j][2][0] = vx;
- vertices[i][j][2][1] = vy+kdy;
- vertices[i][j][3][0] = vx+kdx;
- vertices[i][j][3][1] = vy+kdy;
- texcoords[i][j][0][0] = tx;
- texcoords[i][j][0][1] = ty+1.0/6.0;
- texcoords[i][j][1][0] = tx+1.0/4.0;
- texcoords[i][j][1][1] = ty+1.0/6.0;
- texcoords[i][j][2][0] = tx;
- texcoords[i][j][2][1] = ty;
- texcoords[i][j][3][0] = tx+1.0/4.0;
- texcoords[i][j][3][1] = ty;
- yOut[i][j] = 0;
- dyOut[i][j] = 0;
+ glLoadIdentity();
+
+ // Setup vertex data
+ int i, j;
+ const float kdx = 2.0/4.0;
+ const float kdy = 3.0/6.0; // yes, they are same because parts are square, but here for completeness
+ for (i=0; i<4; i++) {
+ for (j=0; j<6; j++) {
+ float vx = -1.0+kdx*i;
+ float vy = -1.5+kdy*j;
+ float tx = i/4.0;
+ float ty = (5-j)/6.0;
+ vertices[i][j][0][0] = vx;
+ vertices[i][j][0][1] = vy;
+ vertices[i][j][1][0] = vx+kdx;
+ vertices[i][j][1][1] = vy;
+ vertices[i][j][2][0] = vx;
+ vertices[i][j][2][1] = vy+kdy;
+ vertices[i][j][3][0] = vx+kdx;
+ vertices[i][j][3][1] = vy+kdy;
+ texcoords[i][j][0][0] = tx;
+ texcoords[i][j][0][1] = ty+1.0/6.0;
+ texcoords[i][j][1][0] = tx+1.0/4.0;
+ texcoords[i][j][1][1] = ty+1.0/6.0;
+ texcoords[i][j][2][0] = tx;
+ texcoords[i][j][2][1] = ty;
+ texcoords[i][j][3][0] = tx+1.0/4.0;
+ texcoords[i][j][3][1] = ty;
+ yOut[i][j] = 0;
+ dyOut[i][j] = 0;
#ifdef ENABLE_PHASE_IN
- if (j)
- yIn[i][j] = yIn[i][j-1]+3.0/6.0+(rand()%200)/500.0;
- else
- yIn[i][j] = 3.0+3.0/6.0+(rand()%200)/500.0;
+ if (j)
+ yIn[i][j] = yIn[i][j-1]+3.0/6.0+(rand()%200)/500.0;
+ else
+ yIn[i][j] = 3.0+3.0/6.0+(rand()%200)/500.0;
#endif
- }
- }
-
- // Activate the vertex data
- glVertexPointer(2, GL_FLOAT, 0, vertices);
- glEnableClientState(GL_VERTEX_ARRAY);
- glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ }
+ }
+
+ // Activate the vertex data
+ glVertexPointer(2, GL_FLOAT, 0, vertices);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
// GL context is active and screen texture bound to be used
- (BOOL)drawTransitionFrameWithTextureFrom:(GLuint)textureFromView
- textureTo:(GLuint)textureToView
+ textureTo:(GLuint)textureToView
{
- int i, j;
-
- for (i=0; i<4; i++) {
- for (j=0; j<6; j++) {
- glPushMatrix();
- glTranslatef(0, -yOut[i][j], 0);
- glDrawArrays(GL_TRIANGLE_STRIP, (i*6+j)*4, 4);
- glPopMatrix();
- }
- }
- BOOL allAreGone = YES;
- for (j=0; j<6; j++) {
- int moved = 0;
- for (i=0; i<4; i++) {
- if (dyOut[i][j] > 0.0) {
- yOut[i][j] += dyOut[i][j];
- dyOut[i][j] *= 1.1;
- moved++;
- }
+ int i, j;
+
+ for (i=0; i<4; i++) {
+ for (j=0; j<6; j++) {
+ glPushMatrix();
+ glTranslatef(0, -yOut[i][j], 0);
+ glDrawArrays(GL_TRIANGLE_STRIP, (i*6+j)*4, 4);
+ glPopMatrix();
+ }
+ }
+ BOOL allAreGone = YES;
+ for (j=0; j<6; j++) {
+ int moved = 0;
+ for (i=0; i<4; i++) {
+ if (dyOut[i][j] > 0.0) {
+ yOut[i][j] += dyOut[i][j];
+ dyOut[i][j] *= 1.1;
+ moved++;
+ }
#ifdef ENABLE_PHASE_IN
- if (yOut[i][j] < 0.5)
- allAreGone = NO;
+ if (yOut[i][j] < 0.5)
+ allAreGone = NO;
#else
- if (yOut[i][j] < 3.0)
- allAreGone = NO;
+ if (yOut[i][j] < 3.0)
+ allAreGone = NO;
#endif
- }
- if (moved<4) {
- if (rand()%100 > 50) {
- while (1) { // naïve loop to find a none moving square
- i = rand()%4;
- if (!(dyOut[i][j] > 0.0)) {
- dyOut[i][j] = 0.02;
- break; // got one, leave now
- }
- }
- }
- break; // no more moving squares, leave outer loop
- }
- }
-
+ }
+ if (moved<4) {
+ if (rand()%100 > 50) {
+ while (1) { // naïve loop to find a none moving square
+ i = rand()%4;
+ if (!(dyOut[i][j] > 0.0)) {
+ dyOut[i][j] = 0.02;
+ break; // got one, leave now
+ }
+ }
+ }
+ break; // no more moving squares, leave outer loop
+ }
+ }
+
#ifdef ENABLE_PHASE_IN
-
- glBindTexture(GL_TEXTURE_2D, textureToView);
-
- if (allAreGone) {
- for (i=0; i<4; i++) {
- for (j=0; j<6; j++) {
- glPushMatrix();
- glTranslatef(0, yIn[i][j], 0);
- glDrawArrays(GL_TRIANGLE_STRIP, (i*6+j)*4, 4);
- glPopMatrix();
- yIn[i][j] -= 0.05;
- if (yIn[i][j] < 0.0) {
- yIn[i][j] = 0.0;
- } else {
- allAreGone = NO;
- }
- }
- }
- }
-
+
+ glBindTexture(GL_TEXTURE_2D, textureToView);
+
+ if (allAreGone) {
+ for (i=0; i<4; i++) {
+ for (j=0; j<6; j++) {
+ glPushMatrix();
+ glTranslatef(0, yIn[i][j], 0);
+ glDrawArrays(GL_TRIANGLE_STRIP, (i*6+j)*4, 4);
+ glPopMatrix();
+ yIn[i][j] -= 0.05;
+ if (yIn[i][j] < 0.0) {
+ yIn[i][j] = 0.0;
+ } else {
+ allAreGone = NO;
+ }
+ }
+ }
+ }
+
#endif
-
- return !allAreGone;
+
+ return !allAreGone;
}
#if 0
- (void)transitionEnded
{
- NSLog(@"transitionEnded");
+ NSLog(@"transitionEnded");
}
#endif
View
54 src/EPGLTransitionView.h
@@ -34,10 +34,10 @@
- (void)setupTransition;
// 'textureFromView' is already active (bind)
-// If no second texture was prepared 'textureTo' will not be valid
+// If no second texture was prepared 'textureToView' will not be valid
// return NO to end transition
- (BOOL)drawTransitionFrameWithTextureFrom:(GLuint)textureFromView
- textureTo:(GLuint)textureToView;
+ textureTo:(GLuint)textureToView;
@optional
- (void)transitionEnded;
@@ -46,39 +46,39 @@
@interface EPGLTransitionView : UIView
{
@private
- id<EPGLTransitionViewDelegate> delegate;
-
- BOOL animating;
- BOOL displayLinkSupported;
- NSInteger transitionFrameInterval;
- id displayLink;
+ id<EPGLTransitionViewDelegate> delegate;
+
+ BOOL animating;
+ BOOL displayLinkSupported;
+ NSInteger transitionFrameInterval;
+ id displayLink;
NSTimer *animationTimer;
-
- EAGLContext *context;
-
- GLint backingWidth;
- GLint backingHeight;
-
- GLuint defaultFramebuffer;
- GLuint colorRenderbuffer;
-
- GLuint textureFromView;
- GLuint textureToView;
-
- CGSize size;
-
- GLfloat clearColor[4];
+
+ EAGLContext *context;
+
+ GLint backingWidth;
+ GLint backingHeight;
+
+ GLuint defaultFramebuffer;
+ GLuint colorRenderbuffer;
+
+ GLuint textureFromView;
+ GLuint textureToView;
+
+ CGSize size;
+
+ GLfloat clearColor[4];
}
@property (readonly, nonatomic, getter=isAnimating) BOOL animating;
@property (nonatomic) NSInteger transitionFrameInterval;
- (id) initWithView:(UIView*)view
- delegate:(id<EPGLTransitionViewDelegate>)delegate;
+ delegate:(id<EPGLTransitionViewDelegate>)delegate;
- (void) prepareTextureTo:(UIView*)view;
- (void) startTransition;
- (void) setClearColorRed:(GLfloat)red
- green:(GLfloat)green
- blue:(GLfloat)blue
- alpha:(GLfloat)alpha;
+ green:(GLfloat)green
+ blue:(GLfloat)blue
+ alpha:(GLfloat)alpha;
@end
View
428 src/EPGLTransitionView.m
@@ -37,220 +37,220 @@ + (Class) layerClass
}
- (id)initWithView:(UIView*)view
- delegate:(id<EPGLTransitionViewDelegate>)_delegate;
+ delegate:(id<EPGLTransitionViewDelegate>)_delegate;
{
if ((self = [super initWithFrame:view.frame]))
- {
- size = view.frame.size;
- delegate = _delegate;
- [delegate retain];
- [self setClearColorRed:0.0
- green:0.0
- blue:0.0
- alpha:0.0];
-
- // Get a image of the screen
- UIGraphicsBeginImageContext(view.bounds.size);
- [view.layer renderInContext:UIGraphicsGetCurrentContext()];
- UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
-
- // Allocate some memory for the texture
- GLubyte *textureData = (GLubyte*)calloc(512*4, 512);
-
- // Create a drawing context to draw image into texture memory
- CGContextRef textureContext = CGBitmapContextCreate(textureData,
- 512,
- 512,
- 8,
- 512*4,
- CGImageGetColorSpace(image.CGImage),
- kCGImageAlphaPremultipliedLast);
- CGContextDrawImage(textureContext,
- CGRectMake(0, 512-size.height, size.width, size.height),
- image.CGImage);
- CGContextRelease(textureContext);
- // ...done creating the texture data
-
- CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
+ {
+ size = view.frame.size;
+ delegate = _delegate;
+ [delegate retain];
+ [self setClearColorRed:0.0
+ green:0.0
+ blue:0.0
+ alpha:0.0];
+
+ // Get a image of the screen
+ UIGraphicsBeginImageContext(view.bounds.size);
+ [view.layer renderInContext:UIGraphicsGetCurrentContext()];
+ UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+
+ // Allocate some memory for the texture
+ GLubyte *textureData = (GLubyte*)calloc(512*4, 512);
+
+ // Create a drawing context to draw image into texture memory
+ CGContextRef textureContext = CGBitmapContextCreate(textureData,
+ 512,
+ 512,
+ 8,
+ 512*4,
+ CGImageGetColorSpace(image.CGImage),
+ kCGImageAlphaPremultipliedLast);
+ CGContextDrawImage(textureContext,
+ CGRectMake(0, 512-size.height, size.width, size.height),
+ image.CGImage);
+ CGContextRelease(textureContext);
+ // ...done creating the texture data
+
+ CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
+
+ self.userInteractionEnabled = NO;
- self.userInteractionEnabled = NO;
-
eaglLayer.opaque = NO;
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking,
- kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
-
- // Create a renderer with texture data for a screen shot
- context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
+ [NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking,
+ kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
+
+ // Create a renderer with texture data for a screen shot
+ context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
if (!context || ![EAGLContext setCurrentContext:context])
- {
+ {
[self release];
return nil;
}
-
- glGenTextures(1, &textureFromView);
- glBindTexture(GL_TEXTURE_2D, textureFromView);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData);
-
- // free texture data which is by now copied into the GL context
- free(textureData);
-
- glGenFramebuffersOES(1, &defaultFramebuffer);
- glGenRenderbuffersOES(1, &colorRenderbuffer);
- glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);
- glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
- glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES,
- GL_COLOR_ATTACHMENT0_OES,
- GL_RENDERBUFFER_OES,
- colorRenderbuffer);
-
- glViewport(0, 0, size.width, size.height);
-
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glScalef(size.width/512.0, size.height/512.0, 1.0); // Convert to screen part of the 512x512 texture
- glMatrixMode(GL_MODELVIEW);
-
- // setup delegate now when GL context is active
- [delegate setupTransition];
-
- [view.window addSubview:self];
-
- animating = FALSE;
- displayLinkSupported = FALSE;
- transitionFrameInterval = 1;
- displayLink = nil;
- animationTimer = nil;
-
- // A system version of 3.1 or greater is required to use CADisplayLink. The NSTimer
- // class is used as fallback when it isn't available.
- NSString *reqSysVer = @"3.1";
- NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
- if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
- displayLinkSupported = TRUE;
+
+ glGenTextures(1, &textureFromView);
+ glBindTexture(GL_TEXTURE_2D, textureFromView);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData);
+
+ // free texture data which is by now copied into the GL context
+ free(textureData);
+
+ glGenFramebuffersOES(1, &defaultFramebuffer);
+ glGenRenderbuffersOES(1, &colorRenderbuffer);
+ glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);
+ glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
+ glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES,
+ GL_COLOR_ATTACHMENT0_OES,
+ GL_RENDERBUFFER_OES,
+ colorRenderbuffer);
+
+ glViewport(0, 0, size.width, size.height);
+
+ glMatrixMode(GL_TEXTURE);
+ glLoadIdentity();
+ glScalef(size.width/512.0, size.height/512.0, 1.0); // Convert to screen part of the 512x512 texture
+ glMatrixMode(GL_MODELVIEW);
+
+ // setup delegate now when GL context is active
+ [delegate setupTransition];
+
+ [view.window addSubview:self];
+
+ animating = FALSE;
+ displayLinkSupported = FALSE;
+ transitionFrameInterval = 1;
+ displayLink = nil;
+ animationTimer = nil;
+
+ // A system version of 3.1 or greater is required to use CADisplayLink. The NSTimer
+ // class is used as fallback when it isn't available.
+ NSString *reqSysVer = @"3.1";
+ NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
+ if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
+ displayLinkSupported = TRUE;
}
-
+
return self;
}
- (void) prepareTextureTo:(UIView*)view
{
- // Get a image of the screen
- UIGraphicsBeginImageContext(view.bounds.size);
- [view.layer renderInContext:UIGraphicsGetCurrentContext()];
- UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
-
- // Allocate some memory for the texture
- GLubyte *textureData = (GLubyte*)calloc(512*4, 512);
-
- // Create a drawing context to draw image into texture memory
- CGContextRef textureContext = CGBitmapContextCreate(textureData,
- 512,
- 512,
- 8,
- 512*4,
- CGImageGetColorSpace(image.CGImage),
- kCGImageAlphaPremultipliedLast);
- CGContextDrawImage(textureContext,
- CGRectMake(0, 512-size.height, size.width, size.height),
- image.CGImage);
- CGContextRelease(textureContext);
- // ...done creating the texture data
-
- [EAGLContext setCurrentContext:context];
-
- glGenTextures(1, &textureToView);
- glBindTexture(GL_TEXTURE_2D, textureToView);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData);
-
- // free texture data which is by now copied into the GL context
- free(textureData);
+ // Get a image of the screen
+ UIGraphicsBeginImageContext(view.bounds.size);
+ [view.layer renderInContext:UIGraphicsGetCurrentContext()];
+ UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+
+ // Allocate some memory for the texture
+ GLubyte *textureData = (GLubyte*)calloc(512*4, 512);
+
+ // Create a drawing context to draw image into texture memory
+ CGContextRef textureContext = CGBitmapContextCreate(textureData,
+ 512,
+ 512,
+ 8,
+ 512*4,
+ CGImageGetColorSpace(image.CGImage),
+ kCGImageAlphaPremultipliedLast);
+ CGContextDrawImage(textureContext,
+ CGRectMake(0, 512-size.height, size.width, size.height),
+ image.CGImage);
+ CGContextRelease(textureContext);
+ // ...done creating the texture data
+
+ [EAGLContext setCurrentContext:context];
+
+ glGenTextures(1, &textureToView);
+ glBindTexture(GL_TEXTURE_2D, textureToView);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData);
+
+ // free texture data which is by now copied into the GL context
+ free(textureData);
}
- (NSInteger) transitionFrameInterval
{
- return transitionFrameInterval;
+ return transitionFrameInterval;
}
- (void)stopTransition
{
- if (animating)
- {
- if (displayLinkSupported)
- {
- [displayLink invalidate];
- displayLink = nil;
- }
- else
- {
- [animationTimer invalidate];
- animationTimer = nil;
- }
-
- animating = FALSE;
- }
+ if (animating)
+ {
+ if (displayLinkSupported)
+ {
+ [displayLink invalidate];
+ displayLink = nil;
+ }
+ else
+ {
+ [animationTimer invalidate];
+ animationTimer = nil;
+ }
+
+ animating = FALSE;
+ }
}
- (void) setTransitionFrameInterval:(NSInteger)frameInterval
{
- if (frameInterval >= 1)
- {
- transitionFrameInterval = frameInterval;
-
- if (animating)
- {
- [self stopTransition];
- [self startTransition];
- }
- }
+ if (frameInterval >= 1)
+ {
+ transitionFrameInterval = frameInterval;
+
+ if (animating)
+ {
+ [self stopTransition];
+ [self startTransition];
+ }
+ }
}
- (void) startTransition
{
- if (!animating)
- {
- if (displayLinkSupported)
- {
- displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(drawView:)];
- [displayLink setFrameInterval:transitionFrameInterval];
- [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
- }
- else
- animationTimer = [NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval)((1.0 / 60.0) * transitionFrameInterval) target:self selector:@selector(drawView:) userInfo:nil repeats:TRUE];
-
- animating = TRUE;
- }
+ if (!animating)
+ {
+ if (displayLinkSupported)
+ {
+ displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(drawView:)];
+ [displayLink setFrameInterval:transitionFrameInterval];
+ [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
+ }
+ else
+ animationTimer = [NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval)((1.0 / 60.0) * transitionFrameInterval) target:self selector:@selector(drawView:) userInfo:nil repeats:TRUE];
+
+ animating = TRUE;
+ }
}
- (void) dealloc
{
- [delegate release];
-
- if (defaultFramebuffer)
- {
- glDeleteFramebuffersOES(1, &defaultFramebuffer);
- defaultFramebuffer = 0;
- }
-
- if (colorRenderbuffer)
- {
- glDeleteRenderbuffersOES(1, &colorRenderbuffer);
- colorRenderbuffer = 0;
- }
-
- if ([EAGLContext currentContext] == context)
+ [delegate release];
+
+ if (defaultFramebuffer)
+ {
+ glDeleteFramebuffersOES(1, &defaultFramebuffer);
+ defaultFramebuffer = 0;
+ }
+
+ if (colorRenderbuffer)
+ {
+ glDeleteRenderbuffersOES(1, &colorRenderbuffer);
+ colorRenderbuffer = 0;
+ }
+
+ if ([EAGLContext currentContext] == context)
[EAGLContext setCurrentContext:nil];
-
- [context release];
- context = nil;
-
+
+ [context release];
+ context = nil;
+
[super dealloc];
}
@@ -259,36 +259,36 @@ - (BOOL) render
[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);
-
- glClearColor(clearColor[0],
- clearColor[1],
- clearColor[2],
- clearColor[3]);
+
+ glClearColor(clearColor[0],
+ clearColor[1],
+ clearColor[2],
+ clearColor[3]);
glClear(GL_COLOR_BUFFER_BIT);
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, textureFromView);
-
- BOOL drawOK = [delegate drawTransitionFrameWithTextureFrom:textureFromView
- textureTo:textureToView];
+ glEnable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, textureFromView);
+
+ BOOL drawOK = [delegate drawTransitionFrameWithTextureFrom:textureFromView
+ textureTo:textureToView];
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
-
- return drawOK;
+
+ return drawOK;
}
- (BOOL) resizeFromLayer:(CAEAGLLayer *)layer
-{
-
+{
+
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:layer];
- glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
+ glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
-
+
if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES)
- {
- NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
+ {
+ NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
return NO;
}
@@ -297,34 +297,34 @@ - (BOOL) resizeFromLayer:(CAEAGLLayer *)layer
- (void) drawView:(id)sender
{
- if ([self render] == NO) {
- [self stopTransition];
- if (delegate &&
- [delegate respondsToSelector:@selector(transitionEnded)])
- [delegate transitionEnded];
- [self removeFromSuperview];
- }
+ if ([self render] == NO) {
+ [self stopTransition];
+ if (delegate &&
+ [delegate respondsToSelector:@selector(transitionEnded)])
+ [delegate transitionEnded];
+ [self removeFromSuperview];
+ }
}
- (void) layoutSubviews
{
- [self resizeFromLayer:(CAEAGLLayer*)self.layer];
+ [self resizeFromLayer:(CAEAGLLayer*)self.layer];
[self drawView:nil];
}
- (void) setClearColorRed:(GLfloat)red
- green:(GLfloat)green
- blue:(GLfloat)blue
- alpha:(GLfloat)alpha
+ green:(GLfloat)green
+ blue:(GLfloat)blue
+ alpha:(GLfloat)alpha
{
- clearColor[0] = red;
- clearColor[1] = green;
- clearColor[2] = blue;
- clearColor[3] = alpha;
- if (alpha > 0.9) {
- CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
- eaglLayer.opaque = YES;
- }
+ clearColor[0] = red;
+ clearColor[1] = green;
+ clearColor[2] = blue;
+ clearColor[3] = alpha;
+ if (alpha > 0.9) {
+ CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
+ eaglLayer.opaque = YES;
+ }
}
@end
Please sign in to comment.
Something went wrong with that request. Please try again.