方法一、保存成图片
QImage* img=new QImage(WINDOW_WIDTH,WINDOW_HEIGHT,QImage::Format_ARGB32);
uchar* tmpBIT = img->bits();
//从颜色缓冲区中读取数据
int tmpPixelSize = WINDOW_WIDTH*WINDOW_HEIGHT * 4;
char* tmpPixelsBuffer = (char*)malloc(tmpPixelSize);
glReadPixels(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT,GL_RGBA, GL_UNSIGNED_BYTE, tmpPixelsBuffer);
for (int y = WINDOW_HEIGHT-1; y >=0 ; y--)
{
for (int x = 0; x < WINDOW_WIDTH; x++)
{
//蓝色
tmpBIT[0] = tmpPixelsBuffer[(y*WINDOW_WIDTH + x) * 4 + 2];
//绿色
tmpBIT[1] = tmpPixelsBuffer[(y*WINDOW_WIDTH + x) * 4 + 1];
//红色
tmpBIT[2] = tmpPixelsBuffer[(y*WINDOW_WIDTH + x) * 4 + 0];
tmpBIT[3] = 100;//不起作用
tmpBIT += 4;
}
}
//从深度缓冲区读取数据
int tmpPixelSize = WINDOW_WIDTH*W