• Advertisement
Sign in to follow this  

[Solved] glReadPixels doesn't read from FBO

This topic is 2865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I'm trying to read a single pixel from a FBO using glReadPixels but it seems that it's the window frame buffer instead of my FBO that is being read. Here's the code:

//Bind the framebuffer and do some rendering...
//...

//Finish rendering and try to read pixel.

glFinish();
float pixel[3];
glReadBuffer(GL_COLOR_ATTACHMENT0);
glReadPixels(0, 0, 1, 1, GL_RGB, GL_FLOAT, pixel);

//Unbind the framebuffer...


I've tried using pixel buffer objects to perform this, but the behaviour I get is the same. Also, the frame buffer I'm rendering to is framebuffer complete and works fine. What could be the problem? Thanks in advance [Edited by - jcabeleira on March 18, 2010 8:30:10 AM]

Share this post


Link to post
Share on other sites
Advertisement
Have you tried unbinding the FBO *before* you call glReadBuffer/glReadPixels? You might also try glGetError after the glReadPixels call to test whether the operation is successful. The man pages on glReadPixels mentions various error conditions.

Share this post


Link to post
Share on other sites
Thanks, Dave. I solved the problem.

I couldn't unbind the frame buffer as you said because then openGL couldn't know that I wanted to read from that frame buffer, but I took your advice and called glGetError not only for glReadPixels but also for glReadBuffer.
It turns out that glReadBuffer was returning an INVALID_ENUM error. After some research I found that this was cauused by the fact that I was binding all frame buffers on my engine with glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBufferID) instead of glBindFramebuffer(GL_FRAMEBUFFER, frameBufferID) which disabled all from them.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement