PDA

View Full Version : how to split a shadow map by using FBO



chowchow
04-27-2008, 08:43 AM
Hello. I want to render a high resolution shadow map which size is (4096*2)*(4096*2), and then split it to 4 sub shadow maps which sizes are 4096*4096.

Now I have get the lower-left sub shadow map by using FBO, the code is:
void init(GLvoid)
{
glGenFramebuffersEXT(1, &fbo);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);

glGenTextures(1, &img);
glBindTexture(GL_TEXTURE_2D, img);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4096, 4096, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, img, 0);

GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if(status != GL_FRAMEBUFFER_COMPLETE_EXT)
exit(1);

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
void display(void)
{
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);

glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0,0,8192,8192);
glLoadIdentity();

renderFBO();
glPopAttrib();
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}
So, could someone tell me how can I get the other 3 sub shadow maps?
Thanks.