FBO, post processing effects and gluUnproject

I’m adding a glow effect to my scene by rendering to an FBO then blend it to the backbuffer.
Before the use of FBO, I have a code that correctly translates the 2D screen coordinates to 3D objects to achieve selection.
With the use of an FBO, gluUnproject is giving other unusable results.
What could be the reason ?

With the use of an FBO, gluUnproject is giving other unusable results.

gluUnproject, being a part of GLU, was written long before the FBO extensions came into existence. It relies in part on state that is different when an FBO is bound.

What you will need to do instead is use the viewport and depth values you have set, as well as your projection matrix to essentially reverse-transform values the way gluUnproject does. Basically, you need to write a version of gluUnproject.

Disaster to me !

Come on :

@ZbuffeR Thank you very much for the link !

@Alfonse Reinheart,
The previous link posted by BuffeR seems to be the actual implementation (GLU version) of gluUnproject,
I can’t see what would have made the difference when FBO was used.
In concrete terms, I am only seeing purely mathematical code,
there is no “state that is different when an FBO is bound” in it…

With more examination, I discover that gluUnproject is picking the farthest object !

Before Adding FBO => gluUnproject returns nearest object
After adding FBO => gluUnproject returns the farthest object

Where are those smileys ?

Maybe your FBO has no depthbuffer attached…?

So ?

I’ve made a look at the source code and it seems there is a depth buffer attached to FBO :

// initialize depth renderbuffer
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb);


I’ve tested with the gluUnproject version of which source code was posted by ZbuffeR. It works in abscence of FBO but again fails when I create an FBO and blend it to the scene.

However I’ve discovered that the same weird behavior of gluUnproject that was caused by the FBO is the same when I do’nt use FBO but also disable depth testing, ie do not call :


So the use of FBO is sort of disabling depth testing.
Adding the above calls to the FBO rendering code does not solve the issue.