FBO Render error

Started by
2 comments, last by Gluc0se 18 years, 5 months ago
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
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.


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 :-)
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.

This topic is closed to new replies.

Advertisement