PDA

View Full Version : Calling multiple glReadPixels & glDrawArrays on a FBO, in Opengl ES



sanchiski
02-17-2014, 05:43 AM
Hello. In Opengl ES, is it possible to call glReadPixels & glDrawArrayson a FBO several times one after the other?
The issue I'm facing is that I'm getting the image all garbled.

Sample Code:



// Activate Off-Screen FBO
glBindFramebuffer(GL_FRAMEBUFFER, fboHandle);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, textureHandle);
glViewport(0, 0, 640, 480);

// 1st Render
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(filter_A);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 640, 480, 0, GL_RGBA, GL_UNSIGNED_BYTE, in_pixels_A);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glReadPixels(0, 0, 640, 480, GL_RGBA, GL_UNSIGNED_BYTE, out_pixels_A);

// 2st Render
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(filter_B);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 640, 480, 0, GL_RGBA, GL_UNSIGNED_BYTE, in_pixels_B);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glReadPixels(0, 0, 640, 480, GL_RGBA, GL_UNSIGNED_BYTE, out_pixels_B);

// Back to the screen FB
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glActiveTexture(GL_TEXTURE0);