title: glReadPixel (One Pass vs Looping Through Points)
body: <p>I'm pretty new to OpenGL and C++ and have recently been trying to extract depth values from a window I've rendered. I've noticed something funny, and I can't seem to figure out why this is happening.</p>
  
  <p>If I call glReadPixel with "width" and "height" values matching my window size, I get a certain depth map.</p>
  
  <p>However, if I loop through the pixels individually, calling glReadPixel at each point, I get a different depth map. The one I get by doing this is the "correct" one, or at least the depth map I would expect. The one I get by grabbing all the depth values in "one-pass," so to speak, is a horizontally stretched out version of the second.</p>
  
  <p>Here's the essential code I'm using for the "one-pass" method, with a small subsample of my window (10x5 block)</p>
  
  <pre><code>int size = window_height * window_width;
  depth_ = new GLfloat[size];
  glReadBuffer(GL_FRONT);
  glReadPixels(0, 0, 10, 5, GL_DEPTH_COMPONENT, GL_FLOAT, depth_);
  // left to right, bottom to top
  int count = 0;
      for (int j = 0; j &lt; 5; j++){
          for(int i = 0; i &lt; 10; i++){
              myfile &lt;&lt; i &lt;&lt; " " &lt;&lt; j &lt;&lt; " " &lt;&lt; depth_[count] &lt;&lt; std::endl;
              count++;
          }
      }
  </code></pre>
  
  <p>Here's the code I used by looping through each point, and calling glReadPixel individually for each pixel:</p>
  
  <pre><code>glReadBuffer(GL_FRONT);
  float depthPixel;
  for (int j = 0; j &lt; 5; j++){
      for(int i = 0; i &lt; 10; i++){
          glReadPixels(i, j, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &amp;depthPixel);
          myfile &lt;&lt; i &lt;&lt; " " &lt;&lt; j &lt;&lt; " " &lt;&lt; depthPixel &lt;&lt; std::endl;
      }
  }
  </code></pre>
  
  <p>The first few values of text file I save from the "one-pass" method looks like this:</p>
  
  <pre><code>0 0 0.462552  (1)
  1 0 0.463212  
  2 0 0.463831  (2)
  3 0 0.464458  
  4 0 0.46518   (3)
  5 0 0.465858  
  6 0 0.466519  (4)
  </code></pre>
  
  <p>While the second, looping method looks like this:</p>
  
  <pre><code>0 0 0.462552  (1)
  1 0 0.463831  (2)
  2 0 0.46518   (3)
  3 0 0.466519  (4)
  4 0 0.467764
  5 0 0.469067
  6 0 0.47047
  </code></pre>
  
  <p>As you can see, an extra depth value is inserted between each point in the first example, almost as if I'm sampling at twice the rate.</p>
  
  <p>Once again, I'm new to OpenGL and a lot of this stuff, so it's possible that I'm making a very stupid, beginner mistake. Nonetheless, I haven't been able to figure it out on my own.</p>
  
  <p>Can anyone give me a hand?</p>