FBO questions

Started by
22 comments, last by _the_phantom_ 18 years, 6 months ago
I am coding a class for FBO's. I want to render a reflection and refraction texture for water and a depth map. So I have a total of three textures that need to be rendered to. So I am not sure on this but do I need to use glGenRenderbuffersEXT? What is needed to render color textures and a depth texture? I am not understanding what the difference is between framebuffers and renderbuffers. Is one for glReadPixels()? where as the other one just copies to textures? Thanks for any help on clearing up my confusion.
Advertisement
a framebuffer object is an object which holds multiples colour buffer targets, as well as optional depth and stencil targets (currently).

A render buffer is a logical buffer which you can attach to a framebuffer object to render into.

If you want to render to a texture you must attach the texture to colour or depth attachment point of the framebuffer object.

Infomation, as always, is in the spec as well as NV's GDC2005 PDF's linked from the Forum FAQ
Well I think I have the code setup correclty but this is what I am getting for a result when I use FBO's. If I use glCopyTexImage2D it renders correclty.



link
http://img213.imageshack.us/img213/6578/untitled1copy0qu.jpg

link with glCopyTexImage2D
http://img388.imageshack.us/img388/6678/nvidiasky0pb.jpg


And here is my fbo class
void FBO::Init(void){	glGenFramebuffersEXT(1, &fb);    glGenRenderbuffersEXT(1, &depth_rb);	glGenTextures(1, &texture);	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);	glBindTexture(texture_target, texture);		// init texture	glTexParameterf(texture_target, GL_TEXTURE_MIN_FILTER, filterMode);     glTexParameterf(texture_target, GL_TEXTURE_MAG_FILTER, filterMode);    glTexParameterf(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);    glTexParameterf(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);	if(texture_target == GL_TEXTURE_3D)		glTexParameterf(texture_target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);	if(depthTexture)	{        glTexImage2D(texture_target, 0, texInternalFormat, texWidth, texHeight, 0, texFormat, GL_UNSIGNED_BYTE, NULL);        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, texture_target, texture, 0);	}	else	{		glTexImage2D(texture_target, 0, texInternalFormat, texWidth, texHeight, 0, texFormat, GL_FLOAT, NULL);        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, texture_target, texture, 0);	}	// initialize depth renderbuffer    glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb);    glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, texWidth, texHeight);	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_rb);}void FBO::BindBuffer(void){	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);}void FBO::unBindBuffer(void){	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);}void FBO::RenderTexture(void){	glBindTexture(texture_target, texture);
how are you using it?
Quote:Original post by phantom
how are you using it?



I am rendering with clipplanes for my water. I have three seperate FBO objects one for depth, waterReflection, waterRefraction. I need the color textures for the reflection and refraction and the depth texture. I am using GLSL to render the water.
yes, but posting code also helps [smile]
Quote:Original post by phantom
yes, but posting code also helps [smile]


the code for the fbo is already posted
;)
I think he's interested in seeing the code that actually uses your FBO class.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
I went back to using glCopyTexImage2D and it works fine, but kicker is when I use glCopyTexSubImage2D instead of glCopyTexImage2D I see the same results as I do when I am using FBO's? What gives...
You will have to set the viewport and ortho matrices if your target texture size is different from your window-specified framebuffer.

This topic is closed to new replies.

Advertisement