Jump to content
  • Advertisement
Sign in to follow this  
AverageJoeSSU

OpenGL Depth Buffer in FBO not working....

This topic is 3855 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

thats pretty straight forward.... here is the code.

// Setup our FBO
	glGenFramebuffersEXT(1, &fbo);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);

	// Create the render buffer for depth	
	glGenRenderbuffersEXT(1, &depthBuffer);
	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthBuffer);
	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, width, height);
	

	// Now setup the first texture to render to
	glGenTextures(1, &this->Pos0);
	glBindTexture(GL_TEXTURE_2D, this->Pos0);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB,  width, height, 0, GL_RGBA, GL_FLOAT, NULL);
	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_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	
	glBindTexture(GL_TEXTURE_2D, 0);
	// And attach it to the FBO so we can render to it
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, this->Pos0, 0);

	// after that setup the second texture to render to
	glGenTextures(1, &this->Norm1);
	glBindTexture(GL_TEXTURE_2D, this->Norm1);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB,  width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	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_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	
	glBindTexture(GL_TEXTURE_2D, 0);
	// And attach it to the FBO so we can render to it
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, this->Norm1, 0);

	// after that setup the second texture to render to
	glGenTextures(1, &this->Diff2);
	glBindTexture(GL_TEXTURE_2D, this->Diff2);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB,  width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
	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_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

	glBindTexture(GL_TEXTURE_2D, 0);
	// And attach it to the FBO so we can render to it
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_TEXTURE_2D, this->Diff2, 0);

	// Attach the depth render buffer to the FBO as it's depth attachment
	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthBuffer);

	// Define an array which contains the targets we wish to render to...
	mrt[0] = GL_COLOR_ATTACHMENT0_EXT;
	mrt[1] = GL_COLOR_ATTACHMENT1_EXT;  
	mrt[2] = GL_COLOR_ATTACHMENT2_EXT;
	// ... then inform OpenGL that we wish to render to these three targets
	glDrawBuffers(3,mrt);

    glClearDepth(1.0f);	
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);	
	//glClearColor( 1.0f , 1.0f, 1.0f , 0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer
	GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);


glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, Lighting->fbo); glClearColor(1.0f, 0.0f, 1.0f, 0.0f); // Black Background glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer //// Save the view port and set it to the size of the texture glPushAttrib(GL_VIEWPORT_BIT); glViewport(0,0,Lwidth,Lheight); //Rendering...... etc. Am i missing something? i get output but it appears like the depthbuffer is off.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!