Jump to content
  • Advertisement
Sign in to follow this  
MARS_999

FBO questions

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

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.

Share this post


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

Share this post


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


Share this post


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

Share this post


Link to post
Share on other sites
Quote:
Original post by phantom
yes, but posting code also helps [smile]


the code for the fbo is already posted
;)

Share this post


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

Share this post


Link to post
Share on other sites
You will have to set the viewport and ortho matrices if your target texture size is different from your window-specified framebuffer.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!