OpenGL ReadPixels截图不显示我看到的内容

时间:2017-01-09 20:46:34

标签: c++ opengl

我试图按如下方式拍摄OpenGL上下文的屏幕截图:

const int pix = 3 * windowWidth * windowHeight;
  GLfloat *pixels = new GLfloat[pix];

  glReadPixels(0, 0, windowWidth, windowHeight, GL_RGB, GL_FLOAT, pixels);
  pngwriter PNG(windowWidth, windowHeight, 0.0, "screenshot.png");
  size_t x = 1;
  size_t y = 1;
  double R, G, B;
  for (size_t i = 0; i < pix; i++) {
    switch (i % 3) {
      case 2:B = (double) pixels[i];
        break;
      case 1:G = (double) pixels[i];
        break;
      case 0:R = (double) pixels[i];
        PNG.plot(x, y, R, G, B);
        if (x == windowWidth) {
          x = 1;
          y++;
        } else { x++; }
        break;
    }
  }
  PNG.close();

  delete[] pixels;

这就是我所看到的:

Desktop Screenshot

这就是我得到的:

This is what I get

截图中没有出现我的转换?

或者我是以完全错误的方式解决这个问题?

0 个答案:

没有答案