Jump to content
  • Advertisement
Sign in to follow this  
WilyCoder

FBO Render error

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

Can someone with FBO experience explain these rendering errors to me? The donut on the right is rendered from camera position. the one on the left is actually a textured quad. I attached the texture to FBO for 1st pass rendering. It does render, but it looks like no depth info is being stored? I am not using any renderbuffers.... Image hosted by Photobucket.com Image hosted by Photobucket.com

Share this post


Link to post
Share on other sites
Advertisement
Aren't you supposed to attach a renderbuffer to the framebuffer that handles depth? You said you haven't done that? Because that would explain it.


Share this post


Link to post
Share on other sites
I will try that. I thought renderbuffers were for ONLY rendering depth values (like no color is desired, ex: shadowmap).

So if you want color AND depth in a single pass, you attach both renderbuffer and texture?

Thanks :-)

Share this post


Link to post
Share on other sites
Yeah heres some example code

//First allocate the texture
glGenTextures(1, &new_object.texture_id);
glBindTexture(new_object.texture_type, new_object.texture_id);
glTexImage2D(new_object.texture_type, 0, GL_RGBA, new_object.width, new_object.height, 0, GL_RGBA, GL_FLOAT, NULL);

GLfloat filterMode = GL_LINEAR;
glTexParameterf(new_object.texture_type, GL_TEXTURE_MIN_FILTER, filterMode);
glTexParameterf(new_object.texture_type, GL_TEXTURE_MAG_FILTER, filterMode);
glTexParameterf(new_object.texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(new_object.texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

//Create the depth RenderBuffer if requested
if (depthbuffer_enabled != 0)
{
glGenRenderbuffersEXT(1, &new_object.depth_id);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, new_object.depth_id);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, new_object.width, new_object.height);
}

//Then there is the binding stage
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer_id);

if (object.texture_id != NULL)
{
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, object.texture_type, object.texture_id, 0);
}
if (object.depth_id != NULL)
{
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, object.depth_id);
}



The first part initializes the texture, and the part in the if statement attaches a depth buffer. After that you need to bind the two to the same framebuffer. Then when you draw to this framebuffer object, it does both color and depth in the same pass. Also, make sure the depth buffer and texture buffer dimensions match. Then remember to enable GL_DEPTH, though if you're drawing that first torus fine, it's probably already on.

Share this post


Link to post
Share on other sites
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!