Sign in to follow this  
jcabeleira

[Solved] glReadPixels doesn't read from FBO

Recommended Posts

jcabeleira    723
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
Dave Eberly    1173
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
jcabeleira    723
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this