Freeglut:最小化(图标化)时 glReadPixels() 不起作用 window
Freeglut: glReadPixels() does not work when minimizing (iconify) window
我使用 freeglut 在 Windows window 中显示 OpenGL 渲染。我管道的最后一步是使用 glReadPixels()
从我的缓冲区中获取像素以供以后处理(例如存储在视频文件中)。
但是,一旦我使用标准 Windows 最小化按钮将 window 最小化,对 glReadPixels()
的调用就不会读取任何数据,一旦我将 window 恢复到它的可见状态,它再次工作。
如何在 window 最小化的情况下继续渲染?
这是我获取图像数据的方式:
GLint viewPortParams[4];
glGetIntegerv(GL_VIEWPORT, viewPortParams);
const int width = viewPortParams[2];
const int height = viewPortParams[3];
// outImage is a cv::Mat* which stores image data as matrix
outImage->create(height, width, CV_8UC3);
// Set it to all grey for debugging - if image stays grey, data has not been fetched.
outImage->setTo(145);
const size_t step = static_cast<size_t>(renderParameters.outImage->step);
const size_t elemSize = renderParameters.outImage->elemSize();
//Set the byte alignment
glPixelStorei(GL_PACK_ALIGNMENT, (step & 3) ? 1 : 4);
//set length of one complete row
glPixelStorei(GL_PACK_ROW_LENGTH, step / elemSize);
glFlush(); //the flush before and after are to prevent unintentional flipping
glReadBuffer(GL_BACK);
glReadPixels(0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE, outImage->data);
/*
* Now, outImage->data does contain the desired image if window is normal
* but stays grey (i.e. the value 145 set above) if minimized
*/
glFlush();
glutSwapBuffers();
有趣的旁注:使用完全屏幕外的管道(使用 glutHideWindow()
)确实有效 - 图像数据被正确检索
However, as soon as I minimize the window using the standard Windows minimize button, the call to glReadPixels() does not read any data and as soon as I restore the window to its visible state, it works again.
是的,这就是它的工作原理。渲染仅发生在通过像素所有权测试的像素上(即属于屏幕外缓冲区的像素,屏幕上 window 的像素实际上对用户可见)。
How can I continue rendering even if the window is minimized?
渲染到帧缓冲区对象(为您提供屏幕外缓冲区),然后从中读取。
我使用 freeglut 在 Windows window 中显示 OpenGL 渲染。我管道的最后一步是使用 glReadPixels()
从我的缓冲区中获取像素以供以后处理(例如存储在视频文件中)。
但是,一旦我使用标准 Windows 最小化按钮将 window 最小化,对 glReadPixels()
的调用就不会读取任何数据,一旦我将 window 恢复到它的可见状态,它再次工作。
如何在 window 最小化的情况下继续渲染?
这是我获取图像数据的方式:
GLint viewPortParams[4];
glGetIntegerv(GL_VIEWPORT, viewPortParams);
const int width = viewPortParams[2];
const int height = viewPortParams[3];
// outImage is a cv::Mat* which stores image data as matrix
outImage->create(height, width, CV_8UC3);
// Set it to all grey for debugging - if image stays grey, data has not been fetched.
outImage->setTo(145);
const size_t step = static_cast<size_t>(renderParameters.outImage->step);
const size_t elemSize = renderParameters.outImage->elemSize();
//Set the byte alignment
glPixelStorei(GL_PACK_ALIGNMENT, (step & 3) ? 1 : 4);
//set length of one complete row
glPixelStorei(GL_PACK_ROW_LENGTH, step / elemSize);
glFlush(); //the flush before and after are to prevent unintentional flipping
glReadBuffer(GL_BACK);
glReadPixels(0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE, outImage->data);
/*
* Now, outImage->data does contain the desired image if window is normal
* but stays grey (i.e. the value 145 set above) if minimized
*/
glFlush();
glutSwapBuffers();
有趣的旁注:使用完全屏幕外的管道(使用 glutHideWindow()
)确实有效 - 图像数据被正确检索
However, as soon as I minimize the window using the standard Windows minimize button, the call to glReadPixels() does not read any data and as soon as I restore the window to its visible state, it works again.
是的,这就是它的工作原理。渲染仅发生在通过像素所有权测试的像素上(即属于屏幕外缓冲区的像素,屏幕上 window 的像素实际上对用户可见)。
How can I continue rendering even if the window is minimized?
渲染到帧缓冲区对象(为您提供屏幕外缓冲区),然后从中读取。