This is a continuation of the first FBO tutorial, this time we will use two of them, one for rendering and the other will be used as a feedback buffer, witch if you have seen a disco music video from the seventies you will know what i mean.
Basically a feedback buffer allows you to overdraw this frames rendering with all the previous frames renderings using an alpha blending.
Now normally one would think, why not do it directly into the back buffer, well that’s because you can’t be sure that you will get the previous rendering there after swapping the buffer, and if your triple buffering your in trouble.
A feedback FBO is a comfortable way of getting around that, since data is not shuffled around in them when you swap the buffers.
Although this is a neat effect, but because of all the low precision errors we get we will actually start using a little bit of HDR rendering, int’s not a lot, but it will remove all those artifacts we get but, it’s not full HDR rendering, that is a whole other tutorial with.
So what do you need them,
1.in the init function double up on the number of frame buffers with a simple copy paste and then just add a “2” after each FBO variable.
And because we don’t want any precision down sampling errors we set the internal format on the FBO#2 color buffer texture to GL_RGBA16F_ARB instead of GL_RGBA, this will make the blur look as smooth as ever.
2. just render to FBO#1 as you did in the first tutorial.
3. move the contents of FBO#1 to FBO#2 with an alpha blending like this
|glViewport (0, 0, 512, 512);
Now about ViewOrtho() and ViewPerspective(), you should already be familiar with them if you did the NeHe tutorials, they enable and disable orthographic rendering, very handy indeed.
4. Finally, render FBO#2 to the frame buffer using most of the same stuff besides the blending part that is, note that i also draw a cube instead and that the full screen render has no blue component, this is because i want the cube to be visible.
|glViewport (0, 0, (GLsizei)(g_window->init.width), (GLsizei)(g_window->init.height));
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
There are many other uses for FBO buffers, using them for post processing or advanced blending is not unheard of, multi pass rendering likes them and for HDR it’s almost must.
The double FBO method i use here is good way of doing things, first render to buffer 1 and then post process them in the second one, it’s fairly fast and leaves few artifacts, but this is only if your GPU can take it that is, there are a few new extensions that deals directly with transferring and blending data between two FBOs, but i won’t include them here, not until we get gl 2.1 where these and the fbo extension is merged.
Sit tight, because the next one is about GLSL shaders, and as always check the source for more info and comments on the code.
Download this tutorial for MSVCPP 6.0