您可以使用glReadPixels
将帧缓冲区的像素读取到数组中。之后您需要将数据存储在图像文件中 - 这里有一些代码:
rectangle<int> rect = getViewport();
const int width = rect.width;
const int height = rect.height;
const size_t bytesPerPixel = 3; // RGB
const size_t imageSizeInBytes = bytesPerPixel * size_t(width) * size_t(height);
// Allocate data for pixels
uint8_t* pixels = new uint8_t[imageSizeInBytes];
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels);
// save data to an image
Image img(width, height, pixels);
buw::saveImage(filename, img);
glut 不能直接输出 MP4。