I'm attempting to re-use FBO I have previously used for direct rendering into a texture.
I want to render into this FBO, without affecting the texture and grab the pixels using glReadPixels.
Normally, I would render anything and get the pixels using glReadPixels and it works, but my previous texture gets affected. For this reason, I try to detach the texture from the FBO using glFramebufferTexture2D with handle of texture as 0. After that, glReadPixels returns only black screen, why?
CODE:
Gdx.gl20.glBindFramebuffer(GL20.GL_FRAMEBUFFER, getFBOHandle());
Gdx.gl20.glFramebufferRenderbuffer(GL20.GL_FRAMEBUFFER, GL20.GL_DEPTH_ATTACHMENT, GL20.GL_RENDERBUFFER, getDBOHandle());
//detach texture previously used, if I dont detach, glReadPixels works, but overwrites the texture
Gdx.gl20.glFramebufferTexture2D(GL20.GL_FRAMEBUFFER, GL20.GL_COLOR_ATTACHMENT0, GL20.GL_TEXTURE_2D, 0, 0);
int status = Gdx.gl20.glCheckFramebufferStatus(GL20.GL_FRAMEBUFFER);
if (status != GL20.GL_FRAMEBUFFER_COMPLETE) System.out.println("FBO ATTACHMENT INCOMPLETE");
Gdx.gl20.glViewport(0, 0, 2048, 1500);
//CLEAR SCREEN USING SPECIFIC COLOR TO SEE WHAT HAS BEEN REDRAWN
Gdx.gl20.glClearColor(0.5f, 1, 1, 1);
Gdx.gl20.glClear( GL20.GL_DEPTH_BUFFER_BIT | GL20.GL_COLOR_BUFFER_BIT);
Gdx.gl20.glFlush();
...
glReadPixels follows
...
I'd like to detach the previous texture properly, render something in this FBO and grab pixels, and later use the FBO again for direct rendering into the texture (restore previous state).
How do I achieve that?
- I dont want to create another FBO due to resources limitation
- working with Opengl ES2