noobish FBO question, it just won't use a blue color

Very simple setup with one fbo called test:

setup:

  
test.allocate(ofGetWidth(),ofGetHeight(), GL_RGBA);  
//clear with a black color non transparent  
test.begin(); ofClear(0,0,0,255); test.end();  
  

draw:

  
test.begin();  
ofEnableAlphaBlending();  
//clear blue  
ofClear(0,0,255,255);  
ofFill();  
ofSetColor(255,255,0);  
ofRect(10,10,100,100);  
test.end();  
test.draw(100,100);  

I would expect a blue fbo with a yellow rectangle. However I end up with a yellow rectangle on a black background. Why? What am I missing? :frowning: Drawing directly to screen instead of the Fbo works as expected.

Just noticed the thread as well which might be related: http://forum.openframeworks.cc/t/what-does-ofclear-do/10428/0

after line 09 try adding
ofSetColor(255, 255, 255, 255);

before the

  
test.draw(100,100);   

  • but looking over this again it does seem a little strange.
    going to test this.
  
  
ofSetColor(255, 255, 255);  
test.draw(100,100);  
  

This works for me.

So the reason you were getting black is that you were drawing the fbo with the current color being:
255,255,0 ( yellow )

The FBO background is blue ( 0, 0, 255 ), so when multiplied, the 0 in the blue channel of the yellow draw color, cancels out the blue in the background all together - leaving you with black.

As a general rule you should always do ofSetColor(255, 255, 255);
before drawing an FBO, unless your intentionally wishing to draw it with a tint.

Hope that helps!
Theo

1 Like

Thanks for clearing that up, Theo!