Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ OpenGL ReadPixels屏幕截图没有显示我看到的内容_C++_Opengl - Fatal编程技术网

C++ OpenGL ReadPixels屏幕截图没有显示我看到的内容

C++ OpenGL ReadPixels屏幕截图没有显示我看到的内容,c++,opengl,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.pn

我试图拍摄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;
const int pix=3*窗宽*窗高;
GLfloat*像素=新GLfloat[pix];
glReadPixels(0,0,窗口宽度,窗口高度,GL_RGB,GL_浮点,像素);
pngwriter PNG(windowWidth,windowHeight,0.0,“screenshot.PNG”);
尺寸x=1;
尺寸y=1;
双R,G,B;
对于(大小i=0;i
这就是我所看到的:


这就是我得到的:


我的所有转换都没有出现在截图中


还是我的做法完全错了?

你是否尝试过读取无符号字节而不是浮点数?旁白:我很好奇为什么
x
y
从1开始(并且
x
重置为)而不是0
glReadPixels(0,0,windowWidth,windowHeight,…)
显然是基于0的。你在
i%3==0
R
)的情况下执行绘图,但这是你得到的第一个情况,
G
B
,这个像素还没有被读取。@Weather Vane我同意这很奇怪,但是看起来PngWriter实际上使用了基于1的坐标来进行
plot
功能:“像素的编号从(1,1)开始,一直到(宽度,高度)”我猜
windowWidth
windowHeight
不正确,你如何确定它们?