CelticDaddio. Would you mind if I post my question in your topic. I’ve gotten the same problem and searched for the solution for two days. I have written a code for casting shadow using shadow map. I have ever used FBO for creating depth texture before, so, I use it again in this program. Although, the code has a littile change from the previous, it doesn’t work this time. I search through every posted topic about FBO and follow any suggessions in the forum but it still not work.
This is from my FBO generation and texture binding routine:
fbo = new FramebufferObject();
fbo->Bind();
glGenTextures(1, &offscnTexture);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, offscnTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 512, 512, 0, GL_DEPTH_COMPONENT,
GL_FLOAT, 0);
fbo->AttachTexture(GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, offscnTexture);
fbo->IsValid();
FramebufferObject::Disable();
This is how I render to depth texture:
// Render to texture
fbo->Bind();
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
camera.setUp(45.0, (float)WINDOW_WIDTH / (float)WINDOW_HEIGHT, 1.0f, 1000.0f);
camera.setPosition(50.0, 100.0, 100.0);
camera.lookAt(0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
AddLight();
glEnable(GL_LIGHTING);
glRotatef(angle1++, 0.0, 1.0, 0.0);
teapot->render(SOLID);
FramebufferObject::Disable();
// Render to primary buffer
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Initialize view
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1.0, 1.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(angle2, 0.0, 1.0, 0.0);
glDisable(GL_LIGHTING);
glDisable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, offscnTexture);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex2f(-0.8, -0.8);
glTexCoord2f(1.0, 0.0); glVertex2f(0.8, -0.8);
glTexCoord2f(1.0, 1.0); glVertex2f(0.8, 0.8);
glTexCoord2f(0.0, 1.0); glVertex2f(-0.8, 0.8);
glEnd();
And this is the result:
Can any one tell me what am I do wrong in this code.