FBO renderbuffer how it works

Hi,

I am trying to use the FBO renderbuffer object to render simple Geometric images but it is not working. Don’t know why, please help. Here is my code:

/*/
Initialization
/
/

//generate FBO name (bufferID) and create a buffer objct with the texture name (bufferID)
//RGBA8 RenderBuffer, 24 bit depth RenderBuffer, 256x256
glGenFramebuffersEXT(1, &fb);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);

//Create and attach a color buffer
glGenRenderbuffersEXT(1, &color_tex);

//We must bind color_rb before we call glRenderbufferStorageEXT
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, color_tex);

//The storage format is RGBA8
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA, 256, 256);

//Attach color buffer to FBO
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, color_tex);
//-------------------------
glGenRenderbuffersEXT(1, &depth_rb);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, 256, 256);

//-------------------------
//Attach depth buffer to FBO
[b]glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_rb);

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);[/b] // Switch back to normal framebuffer rendering

checkfbo(); // make shure it all went ok

/*********************************/
Drawing
/*********************************/

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
glClearColor(0.0, 1.0, 0.1, 0.5);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

//-------------------------
glViewport(0, 0, 256, 256);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 256.0, 0.0, 256.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//-------------------------
[b]glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);

//drawing here
glColor3f(0.0, 1.0, 1.0);
glBegin(GL_QUADS);
glVertex2f(0.25, 0.25);
glVertex2f(0.25, 0.75);
glVertex2f(0.75, 0.75);
glVertex2f(0.75, 0.25);
glEnd();

glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 1.0);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, 0.65);
glVertex2f(0.65, 0.65);
glVertex2f(0.65, 0.5);
glEnd();[/b]

// Read from the FBO
[b]GLubyte* pixels = (GLubyte*)malloc(2502504);

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
glReadPixels(0,0, 250,250, GL_BGRA, GL_UNSIGNED_BYTE, pixels);[/b]

// Draw it to the default (window) frame buffer
[b]glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0 );
glRasterPos2d(0, 0);
glDrawPixels(250, 250, GL_BGRA,GL_UNSIGNED_BYTE,pixels);

glFlush()[/b];

Here is see only the Rectangle filled with color specified with API glClearColor(0.0, 1.0, 0.1, 0.5); (Please see attached file) Having now clue why? Please Help … I am tired now. :sleeping:

Have you checked that the draw code actually produces any output ?( minus the FBO bind of course)
For example you still have depth testing on and/or perhaps cull face is enabled?

You draw very little quads in such a big orthographic view. Try an orthographic view which will suit more the space you’re drawing onto.

As BionicBytes said, it’s always a good idea to check what is rendered on screen when you have problems getting what you expected while trying rendering off-screen.

Hi _arts,

Setting up the suitable orthographic view solved the problem. (what stupid mistake).

Both, thanks for your time.