Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android opengl es 2.0中glReadPixels获取错误数据_Android_Android Ndk_Opengl Es 2.0 - Fatal编程技术网

android opengl es 2.0中glReadPixels获取错误数据

android opengl es 2.0中glReadPixels获取错误数据,android,android-ndk,opengl-es-2.0,Android,Android Ndk,Opengl Es 2.0,我从摄像头获取yuv数据,并将其发送到opengl,然后使用片段着色器将数据转换为RGBA格式并在屏幕上显示。一切进展顺利,但当我使用glReadPixels从帧缓冲区到int数组获取RGBA数据时,我得到了错误的数据 // I use VBO to draw glBindBuffer(GL_ARRAY_BUFFER, squareVerticesBufferID); glVertexAttribPointer(gvPositionHandle, 2, GL_FLOAT, GL_FALSE, 0

我从摄像头获取yuv数据,并将其发送到opengl,然后使用片段着色器将数据转换为RGBA格式并在屏幕上显示。一切进展顺利,但当我使用glReadPixels从帧缓冲区到int数组获取RGBA数据时,我得到了错误的数据

// I use VBO to draw
glBindBuffer(GL_ARRAY_BUFFER, squareVerticesBufferID);
glVertexAttribPointer(gvPositionHandle, 2, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(gvPositionHandle);
glBindBuffer(GL_ARRAY_BUFFER, textureVerticesBuferID);
glVertexAttribPointer(gvTextureHandle, 2, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(gvTextureHandle);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, squareVerticesIndexBufferID);
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, 0);

// Then I use glReadPixels to read the RGBA data
unsigned char *returnDataPointer = (unsigned char*) malloc(width * height * 4);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, returnDataPointer);
不幸的是,我得到了错误的数据,数组中的最后几千个元素是0,同样的代码在ios上运行得很好,我错过了什么吗


我在Android 4.0.3上工作,使用NDK中的OpenGL ES 2。

在调用glReadPixels之前调用glFlush?glGetError是否报告任何错误?glGetError不报告任何错误,而我在glReadPixels之前使用glFlush,问题仍然存在。我是否以错误的方式使用glReadPixels?我唯一能想到的是,如果当前绑定的帧缓冲区未完成,则会生成doc:GL\u INVALID\u FRAMEBUFFER\u操作,即glCheckFramebufferStatus的返回值未完成GL\u FRAMEBUFFER\u。我终于解决了这个问题。glViewPort的大小必须与帧缓冲区的大小相同,否则我们将得到错误的数据。在调用glReadPixels之前调用glFlush?glGetError是否报告任何错误?glGetError不报告任何错误,并且我在glReadPixels之前使用了glFlush,问题仍然存在。我是否以错误的方式使用glReadPixels?我唯一能想到的是,如果当前绑定的帧缓冲区未完成,则会生成doc:GL\u INVALID\u FRAMEBUFFER\u操作,即glCheckFramebufferStatus的返回值未完成GL\u FRAMEBUFFER\u。我终于解决了这个问题。glViewPort的大小必须与帧缓冲区的大小相同,否则将得到错误的数据。