【发布时间】:2012-01-04 06:42:43
【问题描述】:
我正在使用 OpenGL 2.1 为 Mac OS X 编写应用程序
我有一个CVOpenGLTextureRef,它保存着我用 GL_QUADS 渲染的纹理,一切正常。
我现在需要确定纹理的哪些像素是黑色的,因此我编写了这段代码来从纹理中读取原始数据:
//"image" is the CVOpenGLTextureRef
GLenum textureTarget = CVOpenGLTextureGetTarget(image);
GLuint textureName = CVOpenGLTextureGetName(image);
glEnable(textureTarget);
glBindTexture(textureTarget, textureName);
GLint textureWidth, textureHeight;
int bytes;
glGetTexLevelParameteriv(textureTarget, 0, GL_TEXTURE_WIDTH, &textureWidth);
glGetTexLevelParameteriv(textureTarget, 0, GL_TEXTURE_HEIGHT, &textureHeight);
bytes = textureWidth*textureHeight;
GLfloat buffer[bytes];
glGetTexImage(textureTarget, 0, GL_LUMINANCE, GL_FLOAT, &buffer);
GLenum error = glGetError();
glGetError() 报告GL_NO_ERROR 但在调用glGetTexImage() 后缓冲区没有变化...它仍然是空白的。
我做错了吗?
请注意,我不能使用glReadPixels(),因为我在渲染之前修改了纹理,我需要获取未修改纹理的原始数据。
编辑:我什至尝试了后续方法,但我仍然有零缓冲区作为输出
unsigned char *buffer = (unsigned char *)malloc(textureWidth * textureHeight * sizeof(unsigned char));
glGetTexImage(textureTarget, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, buffer);
【问题讨论】:
-
你真的在堆栈中分配这样的(大)数组吗?您应该使用 malloc/new 进行分配。
标签: opengl textures pixel core-video glteximage2d