我目前正在尝试使用 OpenGL 编写一个简单的屏幕捕获应用程序。我当前的来源如下所示:
#include <Windows.h>
#include <iostream>
#include <gl/GL.h>
#include <fstream>
using namespace std;
void main()
{
int nWidth = 1920; // use these dimentions, We'll work work out a calculation to get the real dimentions later.
int nHeight = 1080;
unsigned char* buffer;//declair the buffer here plox
int size = nWidth*nHeight*3; //number of bytes the image will take up.
char input;
buffer = (GLubyte *)malloc(size); // acctually assign some RAM for the program
glReadBuffer ( GL_BACK ); //which buffer we are reading from.
glReadPixels ( 0, 0, nWidth, nHeight, GL_RGB, GL_UNSIGNED_BYTE,buffer);
const char* out=(const char*)buffer;
std::ofstream outfile ("out.crw",std::ifstream::binary);
outfile.write (out,size);
cout << out;
cin>> input;
return;
}
它不会产生错误。虽然,GLReadPixels 的返回值是字符“í”,在输出文件中一遍又一遍地重复。“í”的十六进制值是“CD”,“CD”的颜色值是红色205,所以它似乎至少输出了一种颜色。
我期望返回多个值,指示包含多种颜色的图像。我做错了什么?