GLReadPixels返回一个重复出现的错误值
GLReadPixels returns a single,incorrect, value repeated over and over
我目前正在尝试用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,所以它似乎至少输出一种颜色。
我期望返回多个值,指示包含多种颜色的图像。我做错了什么?
即使实际设置了GL上下文,也无法通过OpenGL捕获屏幕。您只能读取您使用GL渲染的内容。GL的帧缓冲区之外的所有内容都无法通过这种方式访问。您将需要使用一些特定于平台的API来进行屏幕捕获。
相关文章:
- C++,我收到一个无法理解的编译器错误
- VSCode-有一个红色下划线,但程序构建和运行正确,并且出现配音错误
- 删除映射和分割错误中的一个过去结束元素
- 为什么我的 heap.h 文件给我一个LNK2001错误?
- 写一个分数类,我无法弄清楚这些错误
- 我在 .h 中有一个枚举类,并且在.cpp错误中有一个运算符重载:与"运算符<<不匹配
- 一个标头库中的错误
- 给定一个整数数组,需要在Max_Heap上运行操作。得到错误"segmentation fault",有什么想法吗?(C++)
- 使用Visual Studio在虚幻引擎中创建一个新的类c ++给了我太多的错误
- 我正在尝试制作一个自平衡机器人,但编译时存在错误。我不知道如何解决它
- 试图修复一个错误,该错误不会让我开始编程其余部分
- MSVC 无法根据模板参数进行数学运算,这是一个错误吗?
- 我正在尝试一个傻瓜 C++ 练习,我遇到了一个错误,说类 'GraduateStudent' 没有任何名为 'advisor' 的字段
- 零四元数和任何向量都不为零的特征积,这是一个错误吗?
- 我有一个线程 1:EXC_BAD_ACCESS(代码 = 1,地址 = 0x8)错误.我认为这是由于内存管理不好.我可以
- 两个线程一个使用流 Api,另一个线程创建文件失败并出现错误ERROR_SHARING_VIOLATION
- 在使用堆栈为下一个最大数字编写代码时面临 SIGSEGV(分段错误)
- LNK2019错误一个DLL链接到MFC DLL
- 错误:一个声明中有多个类型
- 带有两个运算符的C++11模糊错误(一个左值-第二个右值).底部的