DisplayViewController.m 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #import "DisplayViewController.h"
  2. @interface DisplayViewController ()
  3. @end
  4. @implementation DisplayViewController
  5. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  6. {
  7. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  8. if (self) {
  9. // Custom initialization
  10. }
  11. return self;
  12. }
  13. - (void)dealloc
  14. {
  15. [renderer release];
  16. [super dealloc];
  17. }
  18. - (void)loadView
  19. {
  20. CGRect mainScreenFrame = [[UIScreen mainScreen] applicationFrame];
  21. GPUImageView *primaryView = [[[GPUImageView alloc] initWithFrame:mainScreenFrame] autorelease];
  22. self.view = primaryView;
  23. renderer = [[ES2Renderer alloc] initWithSize:[primaryView sizeInPixels]];
  24. textureInput = [[GPUImageTextureInput alloc] initWithTexture:renderer.outputTexture size:[primaryView sizeInPixels]];
  25. filter = [[GPUImagePixellateFilter alloc] init];
  26. [(GPUImagePixellateFilter *)filter setFractionalWidthOfAPixel:0.01];
  27. // filter = [[GPUImageGaussianBlurFilter alloc] init];
  28. // [(GPUImageGaussianBlurFilter *)filter setBlurSize:3.0];
  29. [textureInput addTarget:filter];
  30. [filter addTarget:primaryView];
  31. [renderer setNewFrameAvailableBlock:^{
  32. float currentTimeInMilliseconds = [[NSDate date] timeIntervalSinceDate:startTime] * 1000.0;
  33. [textureInput processTextureWithFrameTime:CMTimeMake((int)currentTimeInMilliseconds, 1000)];
  34. }];
  35. [renderer startCameraCapture];
  36. }
  37. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  38. {
  39. return (interfaceOrientation == UIInterfaceOrientationPortrait);
  40. }
  41. - (void)drawView:(id)sender
  42. {
  43. [renderer renderByRotatingAroundX:0 rotatingAroundY:0];
  44. }
  45. #pragma mark -
  46. #pragma mark Touch-handling methods
  47. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
  48. {
  49. NSMutableSet *currentTouches = [[[event touchesForView:self.view] mutableCopy] autorelease];
  50. [currentTouches minusSet:touches];
  51. // New touches are not yet included in the current touches for the view
  52. lastMovementPosition = [[touches anyObject] locationInView:self.view];
  53. }
  54. - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
  55. {
  56. CGPoint currentMovementPosition = [[touches anyObject] locationInView:self.view];
  57. [renderer renderByRotatingAroundX:(currentMovementPosition.x - lastMovementPosition.x) rotatingAroundY:(lastMovementPosition.y - currentMovementPosition.y)];
  58. lastMovementPosition = currentMovementPosition;
  59. }
  60. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
  61. {
  62. NSMutableSet *remainingTouches = [[[event touchesForView:self.view] mutableCopy] autorelease];
  63. [remainingTouches minusSet:touches];
  64. lastMovementPosition = [[remainingTouches anyObject] locationInView:self.view];
  65. }
  66. - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
  67. {
  68. // Handle touches canceled the same as as a touches ended event
  69. [self touchesEnded:touches withEvent:event];
  70. }
  71. @end