BTW there is just ooooone little "nasty" thing with FBOs:
You don't have any FSAA effects with Framebuffers and the rendering quality is in my opinion (without FSAA) very shitty. There are several solutions to this problem, I found one with shaders but it seems an overkill for just applying a "normal" behaviour with FBO. After hours of googeling I found that the good guys at Khronos Group have already solved this problem for us by extending OpenGL with FSAA-FBOs.
And before you start searching again for examples, here is what I've found on the web - I packed this stuff into a function again:
#define FRAMEBUFFER_MULTISAMPLE 8
...
int createMSAAFBO ( struct FBOELEM *store, int width, int height) {
unsigned int fbo, cbo, dbo;
int maxsamples;
GLenum error;
glGetIntegerv (GL_MAX_SAMPLES_EXT, &maxsamples);
if ( maxsamples > FRAMEBUFFER_MULTISAMPLE )
maxsamples = FRAMEBUFFER_MULTISAMPLE;
glGenFramebuffersEXT (1, &store->fbo);
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, store->fbo);
glGenRenderbuffersEXT (1, &store->colorbuf);
glBindRenderbufferEXT (GL_RENDERBUFFER_EXT, store->colorbuf);
glRenderbufferStorageMultisampleEXT (GL_RENDERBUFFER_EXT, maxsamples, GL_RGBA, width, height);
glGenRenderbuffersEXT (1, &store->depthbuffer);
glBindRenderbufferEXT (GL_RENDERBUFFER_EXT, store->depthbuffer);
glRenderbufferStorageMultisampleEXT (GL_RENDERBUFFER_EXT, maxsamples, GL_DEPTH_COMPONENT, width, height);
glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, store->colorbuf);
glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, store->depthbuffer);
error = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT);
if (error != GL_FRAMEBUFFER_COMPLETE_EXT) {
switch (error) {
case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
MessageBox(NULL, "GL_FRAMEBUFFER_UNSUPPORTED_EXT", "FBO-ERROR", MB_OK | MB_ICONINFORMATION);
break;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
MessageBox(NULL, "GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT", "FBO-ERROR", MB_OK | MB_ICONINFORMATION);
break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
MessageBox(NULL, "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT", "FBO-ERROR", MB_OK | MB_ICONINFORMATION);
break;
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
MessageBox(NULL, "GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT", "FBO-ERROR", MB_OK | MB_ICONINFORMATION);
break;
case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
MessageBox(NULL, "GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT", "FBO-ERROR", MB_OK | MB_ICONINFORMATION);
break;
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
MessageBox(NULL, "GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT", "FBO-ERROR", MB_OK | MB_ICONINFORMATION);
break;
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
MessageBox(NULL, "GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT", "FBO-ERROR", MB_OK | MB_ICONINFORMATION);
break;
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT:
MessageBox(NULL, "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT", "FBO-ERROR", MB_OK | MB_ICONINFORMATION);
break;
default:
MessageBox(NULL, "default:", "FBO-ERROR", MB_OK | MB_ICONINFORMATION);
break;
}
}
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
return (store->fbo);
}
The difference between FSAA FBO's and non-FSAA FBO's is (as you can see in the example above) that you can't bind any textures to this Buffer but you can do a "Blit" to another FBO which has a texture object bound.
void texturizeMSAAFBO ( int source, int dest, int width, int height) {
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, source);
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, dest);
glBlitFramebufferEXT(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0);
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
}
This "Blits" (how I missed this term from good old Amiga) the source-MSAA (or any FBO if you need that) to dest FBO (created by the function of my first posting).
I found another "solution" several days ago, where some guy wrote that he "antialiases" his Screen by creating a FBO with twice size of the Backbuffer. I didn't like the solution so I didn't really tried it out, but I readed in some OGL Specs that FBO Rendering on newer cards should be the fastest solution.