Jump to content
  • Advertisement
Sign in to follow this  
FirstStep

Understanding Framebuffer for beginners

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

Im quite confuse on the custom framebuffer and the default framebuffer of the OpenGL

 

Say for example we created our custom framebuffer.

GLuint framebuffer;
glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureColorbuffer, 0);

in here we just created an FBO and add a texture attachment on it.

 

But in the end of it we had to call the default FBO

glBindFramebuffer(GL_FRAMEBUFFER, 0);

But why? I mean the stored data was on the custom FBO. Why do we have to call the default instead of the custom one? Im confuse. I just cant see the connection of the two. Please, someone  enlighten me.

Share this post


Link to post
Share on other sites
Advertisement

But in the end of it we had to call the default FBO

 

had to? Says who? I think we need some more context here.

Is it from some example code?

Maybe they just wanted to create the extra framebuffer, but then continue to draw on the default framebuffer, and switched back because of that.

 

glBindFramebuffer tells GL which framebuffer to work with (change settings of, or draw to)

 

The default framebuffer is what is shown on the screen.

The first code creates an extra framebuffer which will not be seen on the screen.

Maybe it is used to generate a shadow map (a common usecase) or some other effect.

 

The second code then switches back to work with the default framebuffer.

 

You'd have to switch back (again) to the newly generated framebuffer when you want to draw to that one.

Edited by Olof Hedman

Share this post


Link to post
Share on other sites

had to? Says who? I think we need some more context here.
Is it from some example code?
Maybe they just wanted to create the extra framebuffer, but then continue to draw on the default framebuffer, and switched back because of that.

 

I was actually following this tutorial

 

part of the tutorial stated like this

 

All subsequent rendering operations will now render to the attachments of the currently bound framebuffer. Since our framebuffer is not the default framebuffer, the rendering commands will have no impact on the visual output of your window. For this reason it is called off-screen rendering while rendering to a different framebuffer. To make sure all rendering operations will have a visual impact on the main window we need to make the default framebuffer active again by binding to 0 glBindFramebuffer(GL_FRAMEBUFFER, 0);

 

It is the part that confuses me really. Thats why I could not understand the connection of the custom FBO to the default FBO. 

Edited by FirstStep

Share this post


Link to post
Share on other sites


Maybe they just wanted to create the extra framebuffer, but then continue to draw on the default framebuffer, and switched back because of that.

 

hang on, I am really confuse now. will glfwSwapBuffers swap the custom and the default buffers?

Share this post


Link to post
Share on other sites

glfwSwapBuffers will just swap the buffers of the window (the default buffer)

The custom framebuffer dont have to be double buffered, but will be drawn as part of drawing to the default buffer.

 

Something like this (simplified, it might be more complicated under the hood):

 

- switch to use the offscreen buffer.

- issue draw commands to draw to the custom framebuffer, which is connected to a texture id, this will fill it with contents.

- switch to use the default buffer.

- issue draw commands that use that texture id but draw to the default framebuffer.

- glfwSwapBuffers to flush commands and show it on screen.

 

 

 


To make sure all rendering operations will have a visual impact on the main window we need to make the default framebuffer active again by binding to 0 glBindFramebuffer(GL_FRAMEBUFFER, 0);

 

Not terribly clear I guess, but I think the point of that sentence is that you have to switch back to the default buffer, when you want to draw to that one (to actually show something on the screen that is using the texture you just drew), after you are done drawing to the the custom FBO.

Edited by Olof Hedman

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!