glReadPixels() quot;dataquot; argument usage?(glReadPixels() “数据参数用法?)
问题描述
我正在尝试使用 glReadPixels 从图像中获取颜色数据.我应该使用 glReadPixels 但我似乎无法弄清楚.这是一个更大项目的一部分,但现在我只想知道如何正确使用它.
I'm trying to use glReadPixels to get color data from an image. I'm supposed to be using glReadPixels but I can't seem to figure it out. It's part of a much larger project, but right now all I want is to know how to properly use this.
我查了一下,结果是这样的:
I looked it up and got something like this:
void glReadPixels(GLint x,
GLint y,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type,
GLvoid* data);
但我不确定我应该把什么作为最后一个论点,当我这样做时,我什至会如何使用它.帮助将不胜感激!(即:如何使用它或如何获取颜色的简单示例)
But I'm not sure what I should be putting in as that last argument, and when I do, how I would even use it. Help would really be appreciated! (ie: a simple example of how to use it, or how to get the color)
推荐答案
data 接受一个指向您为 glReadPixels 准备将数据放入的缓冲区的指针.像这样:
data takes a pointer to some buffer you prepared for glReadPixels to put the data into. Like this:
switch(format) {
case GL_BGR:
case GL_RGB:
components = 3; break;
case GL_BGRA:
case GL_RGBA:
components = 4; break;
case GL_ALPHA:
case GL_LUMINANCE:
components = 1; break;
}
GLubyte *data = malloc(components * width * height);
if( data ) {
glReadPixels(0, 0, width, height, format, GL_UNSIGNED_BYTE, data);
}
这篇关于glReadPixels() “数据"参数用法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:glReadPixels() “数据"参数用法?
基础教程推荐
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 提升 ASIO 流缓冲 2021-01-01
- c++ STL设置差异 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
