1

Possible Duplicate:
Why is glReadPixels() failing in this code in iOS 6.0?

The following line works great on the iOS 6 simulator but doesn't work on iOS 6 device. What could be wrong ? How to fix this ? Thanks a lot.

glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
Community
  • 1
  • 1
kal21
  • 461
  • 5
  • 18

1 Answers1

5

Setting YES to kEAGLDrawablePropertyRetainedBacking property for EAGLLayer fixed the problem.

kal21
  • 461
  • 5
  • 18
  • As I comment on one of the answers in the above-linked question, this can have adverse performance implications for your rendering (and is broken on the iPad 3 in iOS 5.x), so I'd avoid this if possible. Instead, make sure you do your screen capture before the render buffer is presented to the screen. It is invalidated after that point. – Brad Larson Sep 28 '12 at 15:55
  • Thank you @BradLarson. In my code the rendering is happening through animation timer while screen capture only happens when user taps on the button. I guess i have to put a flag in the render loop to do screen capture before rendering. – kal21 Sep 28 '12 at 18:39
  • great answer Brad. any chance of also a link to the question this is a dupe of ? – orion elenzil Oct 02 '12 at 14:07
  • just fwiw, note in my app, which is based on the stock openGL example, this meant that calling glReadPixels as the result of a button-press didn't work because by that time the render buffer has been presented. the work-around in my case was just to set bool and call glReadPixels next frame just before presentBuffer(), but that might not be an option for all apps. Also note that if you've worked around the RetainedBacking bug in iPad3 + iOS5.x by rendering to an intermediary texture, you may be able to just get the pixels from there. – orion elenzil Oct 02 '12 at 14:16