Sign in to follow this  
robinei

FBO render to depth texture

Recommended Posts

robinei    187
I set up my depth texture this way:
	glGenTextures(1, &shadowMapTexture);
	glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
	glTexImage2D(	GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, shadowMapSize, shadowMapSize, 0,
					GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);





Then when I've drawn the scene from the light's perspective I do this:
	glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
	glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, shadowMapSize, shadowMapSize);





Now this works but I want to use an FBO instead of glCopyTexSubImage2D. I set it up using this code(where shadowMapTexture is set up as before):
	glGenFramebuffersEXT(1, &shadowBuffer);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, shadowBuffer);
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, shadowMapTexture, 0);
	glDrawBuffer(GL_FALSE);
	glReadBuffer(GL_FALSE);

	GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
	if(status != GL_FRAMEBUFFER_COMPLETE_EXT) {
		fprintf(stderr, "FBO setup failed\n");
		exit(1);
	}

	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);





I now draw the depth texture like this:
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, shadowBuffer);

	// draw scene

	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);





But when I later try to use the shadowMapTexture it doesn't work. I guess I'm working under the assumption that at this point the contents of the shadowMapTexture will be the same as under the glCopyTexSubImage2D method. I use a simple technique where I draw the entire scene in shadow first and then draw normally everything that's not in shadow and now everything is drawn shadowed. Edit: To clarify: There is nothing useful in the texture after doing the FBO method, while there is after the glCopyTexSubImage2D method. [Edited by - robinei on October 13, 2007 1:31:11 PM]

Share this post


Link to post
Share on other sites
robinei    187
I've read around a lot and I can't find anything indicating that I'm doing anything wrong. I've tried both with an ATI and an nVidia machine and neither works.

Can anybody confirm whether or not this is the way you do(or would do) render to depth texture for shadowmapping or whatever purpose, using FBOs?

Share this post


Link to post
Share on other sites
zedz    291
that looks about right (from memory ati doesnt do 16bit shadowmaps i think)

have u tried just rendering in a color FBO + then reusing that texture later on to verify that youre setting up everything correctly

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this