Log in or register to post comments

iOS: glReadPixels works for GLES1 but not GLES2 to grab background frames

March 28, 2012 - 9:09am #1

Hi all,

Weird problem - have switched over a project today from using GLES1 to GLES2, and after converting my different model renderers to ES2, found that while the app looks the same as before, my screenshots no longer include the background (from the camera) - only my models come through.

It's the same when I comment everything out except camera drawing code and screenshot code, as below. I'm taking screenshots using glReadPixels, which comes directly after QCAR::Renderer::getInstance().drawVideoBackground(). As I say, this worked fine in GLES1.1 mode.

Wish I knew what QCAR was doing in the background to draw the video frames as this is really confusing - does it have it's own framebuffer for shader-based video drawing that I therefore can't get my hands on?

An alternative occurs to me that I might be able to take and draw the video frames myself using my own routine, but can't quite be arsed unless there's no other way - any suggestions?

Here's my basic renderFrameQCAR routine (with model drawing stuff excluded as it's commented out at the moment anyway) - if it helps my case:

- (void)renderFrameQCAR
{
  [self setFramebuffer];
		
  // Clear colour and depth buffers
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		
  // Render video background and retrieve tracking state
  QCAR::State state = QCAR::Renderer::getInstance().begin();
  QCAR::Renderer::getInstance().drawVideoBackground();

  if(waitingOnScreenGrab)
  {
    NSLog(@"Delivering screen grab!");
    int32_t* pixelOutputPtr = [screenGrabDelegate provideScreenGrabPixelDataPointer];
    glReadPixels(0, 0, framebufferWidth, framebufferHeight, GL_RGBA, GL_UNSIGNED_BYTE, pixelOutputPtr);
    [screenGrabDelegate glScreenGrabDone];
    waitingOnScreenGrab = NO;
  }
		
  QCAR::Renderer::getInstance().end();
  [self presentFramebuffer];
}
Log in or register to post comments