Simple ofFbo gives very weird result


There’s not much to add besides some very simple code and a screenshot:

#include "testApp.h"  
void testApp::setup(){  
	fbo.allocate(512, 512);  
void testApp::update(){  
void testApp::draw(){  
	ofRect(10, 10, 100, 100);  
	fbo.draw(10, 10);  

What am I doing wrong?

I think you need to clear the contents of the FBO before drawing to it. Try adding
(or whatever you want its contents to be)
right after the call to fbo.begin();


Thanks that works, ofColor(0); and ofColor(1); give the exact same result though, a black background of the Fbo?

Both ofColor and ofClear are available in multiple versions that take a varying number of parameters. The one-parameter version takes a brightness parameter with the range 0-255, which is internally converted into r-g-b components. So there should be a (very) small difference between 0 and 1, either a background color of completely black or a very, very dark gray.

should be:

ofRect(0, 0, ofGetWidth(), ofGetHeight());  

Thanks for the replies.

I still don’t understand ofClear() completely, doing ofClear(255) gives me an all red fbo and I can’t seem to figure out how I’d use it to set a background color for the fbo, or is that not what the color parameters are for?

Dorald your reply suggests maybe I should make an fbo for the exact same size I wan’t something to be displayed? What I’m actually after in the end is the apply a shader on a mesh, reading about it on the internet has brought me this way. And I assumed I should leave some space in the fbo for the actual shader to take place (if the shader would blow up the size of vertices for instance). Am I thinking wrong here?

What ofClear does, as far as I know, is to set all the pixels in the FBO (or the screen if no FBO is “current”) to the value you specify. If you do ofClear(255), it would get completely white (and with an alpha value of 255 for all pixels, if the FBO supports alpha). If you do, say, ofClear(255, 255, 0); you would get and FBO with all-yellow pixels.

However, to actually see the FBO on the screen, you need to draw it to the screen. I think what might be going on is that you aren’t explicitly setting the “drawing color” before calling fbo.draw()? If the current color happens to be red, the contents of the fbo will be tinted red while it is being drawn. Could that be what is happening? That is, if you add a call to ofColor(255); just before the call to fbo.draw(), does the problem go away? This sets the current color to white, causing fbo.draw() to just copy the pixels from the fbo to the screen unchanged.

I’m not sure I understand what you are trying to achieve, but if you want to write to the FBO from a shader, you should make it as large as you want the output of the shader to be.

If I put ofSetColor after fbo.end() and fbo.draw() I get indeed a white background with colored rectangle in it, thanks. I notice ofClear(255); now becomes redundant, do I still need it?

In the end I want to blur a mesh with a shader. I have been told I should display the mesh with an fbo in order to use it as an input for the shader. But I think I just need to read some more about this.