Hi,
I’ve been trying to render the depth buffer to a texture (starting a shadow map implementation), but I keep getting either the unsupported state when creating the FBO. I’m new to this, I’ve tried following http://www.songho.ca/opengl/gl_fbo.html which has a depth-buffer-only solution. I’ve also look at the wiki here and some other resources, but I guess I’m just too confused by it all.
I need my code to be OGL 3.0 compatible, using non-fixed pipeline functionality only. I’m running a nvidia 9300M GS card on WinXP. I have a 3.0 context (3.2 should be supported, had some trouble getting it and settled for 3.0 in the meantime). I use GLEW for extensions.
Any help is really appreciated! Or a working snippet (guaranteed it for OGL 3.0 and newer)
// I requested a 32 bit z-buffer and seemed to have gotten it without trouble
// tried different buffer depths with different texture formats, too, but there
// might be a combination that I've missed
glGenTextures(1, &m_shadowMap);
glBindTexture(GL_TEXTURE_2D, m_shadowMap);
glTexImage2D(
GL_TEXTURE_2D,
0, // mip map levels
GL_DEPTH_COMPONENT32F, // internal format, have tried GL_DEPTH_COMPONENT (no error), too
shadowWidth,
shadowHeight,
0, //border
GL_DEPTH_COMPONENT, // format
GL_FLOAT, // type
NULL); // data
// no error, can create this just fine
Core::CheckError("texture creation");
///////////////////////////////
// second, generate framebuffer
glGenFramebuffers(1, &m_fbo);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
Core::CheckError("framebuffer object");
glGenRenderbuffers(1, &m_renderBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, m_renderBuffer);
Core::CheckError("renderbuffer");
// attachment/storage/whatever
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, shadowWidth, shadowHeight);
glBindRenderbuffer(GL_RENDERBUFFER, 0); // don't really know why I do that, but not having it doesn't help
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_renderBuffer);
Core::CheckError("attachment");
// attach texture to the framebuffer?
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_shadowMap, 0);
// we don't want to render the color buffer
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
// returns 0x00008cdd, which the spec says is FRAMEBUFFER_UNSUPPORTED_EXT
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);