title: Video capture of GLKView view using Frame buffer object stops openGLES content display on screen
body: <p>I am trying to record video of the content that is displayed in GLKView. I am using using Sparrow framework to display the required contents in openGL. I am using framebuffer Object or FBO to get frames from openGLES and write these frame to video using AVAssetwriter. Well I am able to create the video but due to this content display in GLKView has stopped. It is not been refreshed anymore.</p>
  
  <p>What I am doing is:</p>
  
  <p>1.Before I start writing the video I create frameBuffer Object using following method:</p>
  
  <pre><code>-(void)createFBO{
  SPViewController *vC = Sparrow.currentController;
  int contentScaleFactor = Sparrow.contentScaleFactor;
  int width = vC.view.bounds.size.width*contentScaleFactor;
  int height = vC.view.bounds.size.height*contentScaleFactor;
  
  CVReturn err = CVOpenGLESTextureCacheCreate(kCFAllocatorDefault, NULL, [vC context], NULL, &amp;coreVideoTextureCache);
  
  if (err)
  {
      NSAssert(NO, @"Error at CVOpenGLESTextureCacheCreate");
  }
  
  CFDictionaryRef empty; // empty value for attr value.
  CFMutableDictionaryRef attrs;
  empty = CFDictionaryCreate(kCFAllocatorDefault, NULL, NULL, 0, &amp;kCFTypeDictionaryKeyCallBacks, &amp;kCFTypeDictionaryValueCallBacks); // our empty IOSurface properties dictionary
  attrs = CFDictionaryCreateMutable(kCFAllocatorDefault, 1, &amp;kCFTypeDictionaryKeyCallBacks, &amp;kCFTypeDictionaryValueCallBacks);
  CFDictionarySetValue(attrs, kCVPixelBufferIOSurfacePropertiesKey, empty);
  
  err = CVPixelBufferCreate(kCFAllocatorDefault, width, height, kCVPixelFormatType_32BGRA, attrs, &amp;renderTarget);
  if (err)
  {
      NSAssert(NO, @"Error at CVPixelBufferCreate %d", err);
  }
  
  
  CVPixelBufferPoolCreatePixelBuffer (NULL, [assetWriterPixelBufferInput pixelBufferPool], &amp;renderTarget);
  
  CVOpenGLESTextureCacheCreateTextureFromImage (kCFAllocatorDefault, coreVideoTextureCache, renderTarget,
                                                    NULL, // texture attributes
                                                    GL_TEXTURE_2D,
                                                    GL_RGBA, // opengl format
                                                    width,
                                                    height,
                                                    GL_BGRA, // native iOS format
                                                    GL_UNSIGNED_BYTE,
                                                    0,
                                                    &amp;renderTexture);
  
  glBindTexture(CVOpenGLESTextureGetTarget(renderTexture), CVOpenGLESTextureGetName(renderTexture));
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  
  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, CVOpenGLESTextureGetName(renderTexture), 0);
  /////////
  GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
  
  NSAssert(status == GL_FRAMEBUFFER_COMPLETE, @"Incomplete filter FBO: %d", status);
  glBindTexture(GL_TEXTURE_2D, 0);
  CFRelease(attrs);
  CFRelease(empty);
  }
  </code></pre>
  
  <p>2.Then I call the actual writing code in -glkView:drawInRect: method as:</p>
  
  <pre><code>- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
  {
  
  //Check for recording status and write a frame to video
  if (_movieWriter &amp;&amp; _movieWriter.isRecording) {
      [_movieWriter writeCurrentFrameToVideo];
  }
  
  //The code below is unmodified Sparrow-Framework code
  
  @autoreleasepool
  {
      if (!_root)
      {
          // ideally, we'd do this in 'viewDidLoad', but when iOS starts up in landscape mode,
          // the view width and height are swapped. In this method, however, they are correct.
  
          [self readjustStageSize];
          [self createRoot];
      }
  
      [Sparrow setCurrentController:self];
      [EAGLContext setCurrentContext:_context];
  
      glDisable(GL_CULL_FACE);
      glDisable(GL_DEPTH_TEST);
      glEnable(GL_BLEND);
  
      [_support nextFrame];
      [_stage render:_support];
      [_support finishQuadBatch];
  
      if (_statsDisplay)
          _statsDisplay.numDrawCalls = _support.numDrawCalls - 2; // stats display requires 2 itself
  
      #if DEBUG
      [SPRenderSupport checkForOpenGLError];
      #endif
  }
  } 
  </code></pre>
  
  <p>and writing code is:</p>
  
  <pre><code>-(void)writeCurrentFrameToVideo{
  CVPixelBufferLockBaseAddress(renderTarget, 0);
  
  if (!startTime) {
      startTime = [NSDate date];
  }
  CMTime currentTime = CMTimeMakeWithSeconds([[NSDate date] timeIntervalSinceDate:startTime],120);
  //[assetWriterPixelBufferInput appendPixelBuffer:pixelBuffer withPresentationTime:currentTime];
  
  if(![assetWriterPixelBufferInput appendPixelBuffer:renderTarget withPresentationTime:currentTime])
  {
      NSLog(@"Problem appending pixel buffer at time: %lld", currentTime.value);
  }
  else
  {
      NSLog(@"Recorded pixel buffer at time: %lld", currentTime.value);
  }
  
  CVPixelBufferUnlockBaseAddress(renderTarget, 0);
  }
  </code></pre>
  
  <p>I am new to openGLES and don't know much about it.
  Please help.</p>
  
  <p>Thanks</p>