Hello all,
I’ve coded up a simple framebuffer object demo to render a triangle mesh into a depth map, then render that depth map as a texture. I’m using GLUT to do the windowing on OS X 10.6.4 using XCode 3.2.3. Now, when I run the program the entire OS starts behaving sluggishly. Any keyboard or mouse events take seconds to reach the program. Sometimes the screen starts flickering. It appears that the driver just goes haywire. However, a basic FPS counter reports that I’m still getting hundreds of frames per second. (?) Has anyone else seen this/know a fix?
Here is the initialization:
//
// Create the texture.
//
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
TextureWidth, TextureHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
//
// Create the framebuffer and renderbuffer.
//
glGenFramebuffers(1, &fboId);
glBindFramebuffer(GL_FRAMEBUFFER, fboId);
glGenRenderbuffers(1, &rboId);
glBindRenderbuffer(GL_RENDERBUFFER, rboId);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT,
TextureWidth, TextureWidth);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
GL_TEXTURE_2D, textureId, 0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
CheckFramebuffer();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
The call to CheckFramebuffer() reports that the framebuffer object is complete.
Here is my display method:
//
// Pass 1: Render into the framebuffer.
//
glBindFramebuffer(GL_FRAMEBUFFER, fboId);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glPushMatrix();
glTranslatef(0.0, 0.0, -1.5f);
static float angle = 0.0f;
angle += 0.05f;
if (angle > 360.0f) angle -= 360.0f;
glRotatef(angle, 0.0f, 1.0f, 0.0f);
glRotatef(90.0f, 0.0, 0.0f, 1.0f);
glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
glColor3f(1.0f, 0.0f, 0.0f);
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, 0);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
glutSwapBuffers();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glGenerateMipmap(GL_TEXTURE_2D);
//
// Pass 2: Render the depth texture.
//
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0.0f, 0.0f, -1.1f);
glBegin(GL_QUADS);
{
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(+1.0f, -1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(+1.0f, +1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-1.0f, +1.0f, 0.0f);
}
glPopMatrix();
glFlush();
glutSwapBuffers();
The non-framebuffer related portions of code work correctly.
Any insights are appreciated.