Jump to content
  • Advertisement
Sign in to follow this  
Starshine_

How to use QGLFramebufferObject for shadow mapping?

This topic is 3718 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 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
Advertisement
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
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
Just bumping the thread (I hope bumping is allowed here!) because I still don't know how to make the framebuffer work... :(

Share this post


Link to post
Share on other sites
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!