Sign in to follow this  
WilyCoder

FBO Render error

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
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

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