title: Why is glReadPixels so slow and are there any alternative?
body: <p>I need to take sceenshots at every frame and I need very high performance (I'm using freeGlut). What I figured out is that it can be done like this inside <code>glutIdleFunc(thisCallbackFunction)</code></p>
  
  <pre><code>GLubyte *data = (GLubyte *)malloc(3 * m_screenWidth * m_screenHeight);
  glReadPixels(0, 0, m_screenWidth, m_screenHeight, GL_RGB, GL_UNSIGNED_BYTE, data);
  // and I can access pixel values like this: data[3*(x*512 + y) + color] or whatever
  </code></pre>
  
  <p>It does work indeed but I have a huge issue with it, it's really slow. When my window is 512x512 it runs no faster than 90 frames per second when only cube is being rendered, without these two lines it runs at 6500 FPS! If we compare it to irrlicht graphics engine, there I can do this</p>
  
  <pre><code>// irrlicht code
  video::IImage *screenShot = driver-&gt;createScreenShot();
  const uint8_t *data = (uint8_t*)screenShot-&gt;lock();
  // I can access pixel values from data in a similar manner here
  </code></pre>
  
  <p>and 512x512 window runs at 400 FPS even with a huge mesh (Quake 3 Map) loaded! Take into account that I'm using openGL as driver inside irrlicht. To my inexperienced eye it seems like <code>glReadPixels</code> is copying every pixel data from one place to another while <code>(uint8_t*)screenShot-&gt;lock()</code> is just copying a pointer to already existent array. Can I do something similar to latter using freeGlut? I expect it to be faster than irrlicht.</p>
  
  <p>Note that irrlicht uses openGL too (well it offers directX and other options as well but in the example I gave above I used openGL and by the way it was the fastest compared to other options)</p>