Drawing to fbo automatically effects screen without using draw

Hey all,

I’m having a bit of trouble with ofFbo. What I’m trying to do is grab a frame from my webcam and then distort it with some procedurally generated textures. I’m currently tackling this by a) grabbing a frame from the webcam and storing into into a texture, b) using an ofFbo to draw up a texture ‘offscreen,’ and then c) would be blending/combining the webcam texture with the fbo. But I can’t seem to get past step b successfully. If I try to draw to the fbo offscreen, I end up drawing to the screen somehow.

Here’s a snippet of code that causes trouble:

  
void createTestPattern() {  
    testfbo.allocate(width, height, GL_RGBA);  
    testfbo.begin();  
    ofClear(0, 0, 0, 0);  
    ofSetColor(255, 0, 0, 255);  
    ofCircle(width/2, height/2, 100);  
    testfbo.end();  
}  
  
void draw()  {  
ofBackground(ofColor::white);  
  
// Draw ONLY the webcam texture  
webcamTexture.draw(0,0);  
}  

If I run the createTestPattern() function, the webcam texture becomes tinted red when drawn even though I haven’t drawn the fbo to the screen.

The code in more context is on github: https://github.com/mikewesthad/hypersensitive.

It’s because you have set the current drawing color to red in createTestPattern() and this remains as the current draw color.

If you change it to white again before you draw your video you will get the result you want

  
  
void testApp::draw(){  
    ofBackground(ofColor::white);  
ofSetColor(255,255,255,255);  
    mirroredTexture.draw(0,0);  
  
//    m->draw();  
}  
  

Well, that was an easy fix - thank you!

I didn’t realize that setting the draw color would do that. I must not have read the doc carefully enough since it is clearly stated there:

void ofSetColor(int r, int g, int b)

Sets the draw color with r,g,b, 0-255. For example, red (0xff0000) would be: ofSetColor(255,0,0). This affects not only the color of shapes drawn with ofRect(…), ofCircle(…), etc, but also the tint of images and textures.