Sign in to follow this  
Starshine_

How to use QGLFramebufferObject for shadow mapping?

Recommended Posts

Starshine_    122
Hello! I'm trying to do shadow mapping using a QGLFramebufferObject http://doc.trolltech.com/4.3/qglframebufferobject.html but, to be honest, I'm not really sure how to do it. I've read the documentation and tried to do it in my program, but what I did involved a lot of guesswork on how to actually use these framebuffers in practice, and it seems that I guessed something wrong... here's what I'm doing. First, I have a QGLFramebufferObject declared in the private section of my QGLWidget: QGLFramebufferObject *framebuffer; Second, in the initializeGL() function I create a new framebuffer object for the shadow map using this constructor: framebuffer = new QGLFramebufferObject(shadowMapSize, shadowMapSize, QGLFramebufferObject::Depth); And in the paintGL() function, during the first pass (rendering the scene from the light's point of view) I do framebuffer->bind() before rendering the scene, so that it's rendered to the framebuffer, and after that I do framebuffer->release() so that the next pass isn't rendered to the framebuffer anymore. But I have no idea what to do just after rendering the scene... without using the framebuffer, I had this: glBindTexture(GL_TEXTURE_2D, shadowMapTexture); glCopyTexSubImage2D(GL_TEXTURE_2D, 0,0,0,0,0, shadowMapSize, shadowMapSize); But I have no idea how to do that using my new framebuffer object... can someone help me do that?

Share this post


Link to post
Share on other sites
HuntsMan    368
Use QGLFramebufferObject::texture() to get the texture ID of the attached texture, that contains the depth buffer data, and you can glBindTexture it and use it for your shadow algorithms.

Share this post


Link to post
Share on other sites
Starshine_    122
Thanks! I'm getting an error, though... here it is:

QGLFramebufferObject: Framebuffer incomplete attachment.


When I googled for it, I found this: http://lists.trolltech.com/qt-interest/2007-08/thread00134-0.html it seems someome had the same problem, and someone told him to use QGLFramebufferObject::handle(). How can I use the handle here?

Share this post


Link to post
Share on other sites
HuntsMan    368
Simple, if you want to use a depth-only FBO, you need to set the draw/read buffers to GL_NONE, to indicate to OpenGL that you don't want to render to the color buffer, using :

glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);

Then the framebuffer should be complete.

Share this post


Link to post
Share on other sites
Starshine_    122
Thanks! But it doesn't change anything, I still get the "QGLFramebufferObject: Framebuffer incomplete attachment" error... or would it work only if I used the normal framebuffer instead of QGLFramebufferObject?

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