title: glReadPixels store x, y values
body: <p>I'm trying to store pixel data by using glReadPixels, but so far I managed to only store it one pixel at a time. I'm not sure if this is the way to go. I currently have this:</p>
  
  <pre><code>unsigned char pixels[3];
  glReadPixels(50,50, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, pixels);
  </code></pre>
  
  <p>What would be a good way to store it in an array, so that I can get the values like this:</p>
  
  <pre><code>pixels[20][50][0]; // x=20 y=50 -&gt; R value
  pixels[20][50][1]; // x=20 y=50 -&gt; G value
  pixels[20][50][2]; // x=20 y=50 -&gt; B value
  </code></pre>
  
  <p>I guess I could simple put it in a loop:</p>
  
  <pre><code>for ( all pixels on Y axis )
  {
      for ( all pixels in X axis )
      {
          unsigned char pixels[width][height][3];
          glReadPixels(x,y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, pixels[x][y]);
      }
  }
  </code></pre>
  
  <p>But I have the feeling that there must be a much better way to do this. But I do however need my array to be like I described above the code. So would the for loop idea be good, or is there a better way?</p>