glReadPixels()“data”参数用法? [英] glReadPixels() "data" argument usage?
问题描述
我尝试使用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()“data”参数用法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!