Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm presently working on a 3D car racing game for the iOS platform. I had to implement a replay system and then record that replay in a video file to upload it to YouTube.

I'm only having issues with the recording part, the rest is done. What I'm doing is using the glReadPixels() command of OpenGL ES 1.1 to capture the framebuffer content and creating a video from these frames during runtime (using AVFoundation framework).

The problem I'm facing is that I have to call glReadPixels() in each update which is very slow . It decreases the FPS from around 30 to only 2-3... Is there any alternative to the glReadPixels() command? Or did anyone create a replay system and recorded to video?

share|improve this question
up vote 8 down vote accepted

Since you have the replay system in place, I'd suggest you only store the replay-data during gameplay and then render a video from that replay offline. Eg. after the game has finished and the user chooses to post the replay as video, then you would render the video from the replay-data (by playing the replay and using glReadPixels).

share|improve this answer
k this approach is new and deserved to be checked...hey you done this before ? – Tornado Aug 23 '11 at 10:06
No, I haven't done this before. But I would implement the replay system as outlined in this question and then render the frames offscreen, probably using a render to texture approach after the race is over. – bummzack Aug 23 '11 at 11:45
I think most games do this (Starcraft for one definitely does). However, you must make sure that your simulation is totally deterministic, that is, giving a certain set of inputs you will ALWAYS have the same output. Additionally, your replay data is significantly smaller and shareable. – pek Aug 23 '11 at 11:47
@bummzack - the links you provided will be very useful to me...thanks for that – Tornado Aug 23 '11 at 12:31

I think the simplest way is to record user and AI actions and state during gameplay, not actual frames. After gameplay has finished, either the player completing the race or quitting back to the main menu they are given the option to look at a replay (or save one) and only then are those actions used to recreate the frames by playing back the actions and state through the game engine. This has the additional benefit of not (essentially) having to draw each full frame multiple additional times during gameplay.

share|improve this answer
I basically gave the same answer. What distinguishes your approach from mine? – bummzack Aug 23 '11 at 11:34
The one caveat here is if you have a non-deterministic AI. Since it's a racing game, you need to make sure all the AI racers behave the exact same way when you play back the player's replay data. – Apreche Aug 23 '11 at 12:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.