ofTexture loadScreenData()/draw() Fail

Question:
What I want to do is capture the screen to an ofTexture
(defined as ofTexture texColor;) at the end of the draw method and then draw it at the start of the draw method.

Following is the relevant code :

  
  
void testApp::setup(){  
 counter=0;  
 ofBackground(180,180,200);  // THIS IS NOT BLACK  
 texColor.allocate(ofGetWidth(), ofGetHeight(),GL_RGB);    
  
}  
  
void testApp::draw(){  
    if (counter > 1 ) { // don't draw it till something to draw  
        texColor.draw(0,0,ofGetWidth(), ofGetHeight()); // write screen  
       }  
  
  ofCircle(ballPositionX, ballPositionY, 15);  
  
  texColor.loadScreenData(0,0,ofGetWidth(), ofGetHeight());    
  counter++;  
}  
  

The capture and draw seem to work fine except when I do the load it apparently ignores the fact that the background color is not black because when I do the draw, the background becomes black.

So my question is does loadScreenData ignore the screen’s background and only capture what is written to the screen during the course of the draw method?

Of course this makes no sense since if the above is true then turning on ofEnableAlphaBlending() would only send to the screen that which was captured but that does not work either. I still wind up with a black background after executing the texColor.draw().

So why does the combo loadScreenData() / draw() wipe out the background color I set in the setup() method?

Is this an OpenGL problem or is it an oF problem - which is the guilty party?

Thanks.

hi artsnova,

openframeworks runs double-buffered. this means that what you draw in the draw() function doesn’t actually get copied to the screen until the next time through the run loop – that is, just before the draw() method is called. so, none of the new stuff that you draw will be picked up by loadScrenData().

try using FBO’s instead. there’s an ofxFbo addon floating around…