Jump to content
  • Advertisement
Sign in to follow this  
adam17

Depth rendering problems

This topic is 4232 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im about to pull my hair out heh. ive been trying to render the depth of my scene to a texture. ive tried using the fixed function pipeline of ogl and framebuffers and neither work for me. when i do simple "render to texture" i get the correct image. when i use the GL_DEPTH_ATTACHMENT i cant see anything except for some VERY faint gray pixels on the rendered texture. im not sure if there is a problem with the texture format or my framebuffer format.
	glGenFramebuffersEXT(1, &fb);
	glGenTextures(1, &depth_tex);
	glGenRenderbuffersEXT(1, &rb);

	//switch to our fbo so we can bind stuff to it
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);

	tex_dim = 128;
	//create the colorbuffer texture and attach it to the framebuffer
	glBindTexture(GL_TEXTURE_2D, depth_tex);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex_dim, tex_dim, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, tex_dim, tex_dim, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, depth_tex, 0);
        //uncommenting the next line crashes on runtime
	//glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depth_tex, 0);

	//create a render buffer as our depthbuffer and attach it
	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb);
	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, tex_dim, tex_dim);

	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rb);

...and when i render the fbo image
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
	//glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb);
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, depth_tex, 0);
	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rb);

any ideas? thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!