title: Fast Screen Recording of iOS App
body: <p>I'm new to OpenGL ES. 
  I'm trying to write code for screen recording of iOS apps, especially games.</p>
  
  <p>I'm using the 'render to texture' method described with code in <a href="https://stackoverflow.com/a/9704392/707773">this answer</a> to capture screen and write the video for a cocos2d game.
  One modification I made was that, when I call <code>CVOpenGLESTextureCacheCreate</code> then I'm using
  <code>[EAGLContext currentContext]</code>
  instead of </p>
  
  <p><code>[[GPUImageOpenGLESContext sharedImageProcessingOpenGLESContext] context]</code></p>
  
  <p>It does record the video but there are two issues</p>
  
  <p>(1)- When it starts recording then new drawing on the screen stops. I want the app to keep on drawing on the screen too. As I'm new to OpenGL ES, I don't have deep understanding of frame buffer objects etc., so I have a hard time figuring out how to simultaneously draw on screen and capture the screen as well. I'll appreciate a code example in this regard.</p>
  
  <p>(2)- The recorded video is flipped upside down. How can I get it in correct direction?</p>
  
  <p>Previously I considered <code>glReadPixels</code> method too, but that has performance drawbacks.</p>
  
  <p>Update: a couple of  ideas also came to mind. According to my little understanding, </p>
  
  <p>I could simply draw my texture back to screen, but don't know how.</p>
  
  <p>OR</p>
  
  <p>I could have a secondary FBO and I could attach the texture to it, i.e.</p>
  
  <pre><code>glGenFramebuffersOES(1, &amp;textureFrameBuffer);
  glBindFramebufferOES(GL_FRAMEBUFFER_OES, textureFrameBuffer);
  
  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, CVOpenGLESTextureGetName(renderTexture), 0);
  //Then I restore the screen FBO.
  glBindFramebufferOES(GL_FRAMEBUFFER_OES, 1);
  </code></pre>
  
  <p>But if I do that, then how do I copy the screen-drawing to my secondary FBO?</p>