title: Flip an image vertically
body: <p>I'm trying to flip an image vertically, after retrieving the buffer from openGL. It seems to be outputting an incorrect image with the following code:</p>
  
  <pre><code>const int width = 100;
  const int height = width;
  const int components = 3;
  unsigned char pixels[width * height * components];
  glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
  unsigned char flipPixels[width * height * components];
  for (int i = 0; i &lt; width; ++i) {
      for (int j = 0; j &lt; height; ++j) {
          for (int k = 0; k &lt; components; ++k) {
              flipPixels[i + j * width + k] = pixels[(height) * (width) - ((j+1) * width) + i + k];
          }
      }
  }
  </code></pre>
  
  <p>I know I can only iterate half the height and achieve the same, but I want to implement it by going through the complete height of the image. I can't seem to figure out what's wrong with the code. Any help would be appreciated.</p>