Hi,
I’ve been having an issue when trying to use frame buffer objects to render to depth textures. For some reason it takes about a second or two for this to occur. For the purposes of my project, I need to use multiple 2D depth textures. At first I tried to use one FBO and call glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depthTextures[i], 0); each time I need to use a different depth texture. Since this was slow I next created one FBO for each depth texture so that I wasn’t calling this function each frame. Unfortunately this didn’t work.
Here’s my initialization code:
glBindTexture(GL_TEXTURE_2D, depthTextures[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); // Need to reconsider this may want to check for wrapping in shader take care of there.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); // Need to reconsider this
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Since this is linear, the color texture will look anti-aliased
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// Also set up the depth comparison modes
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, texW, 1, 0, GL_DEPTH_COMPONENT, GL_FLOAT, (void*)NULL); // Just save space for it.
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, depthFrameBuffer[i]);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depthTextures[i], 0);
glDrawBuffer(GL_FALSE);
glReadBuffer(GL_FALSE);
GLenum fboStatus = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if (fboStatus != GL_FRAMEBUFFER_COMPLETE_EXT )
{
fprintf(stderr, "FBO ERROR (0x%x)!
", (fboStatus));
}
And here’s where I attempt to render to the textures:
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, depthFrameBuffer[quadrant]);
glViewport(0, 0, 1, texH);
glClear(GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glOrtho(0.0, 1.0, 0.0, texH, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
// ... drawing code ...
glFlush();
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
I’ve been searching the net for a while and I have been unable to find any reason behind this. My card is a NVIDIA Geforce 7600 GT in case that’s of interest. Any ideas would be greatly appreciated.
Thanks.