How to use QGLFramebufferObject for shadow mapping?
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?
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.
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?
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?
Just bumping the thread (I hope bumping is allowed here!) because I still don't know how to make the framebuffer work... :(
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.
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
Then the framebuffer should be complete.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement