ofImage grabScreen getting empty image


#1

Hi there,

So I’m working on updating a very old app. The behavior I’m aiming for is to:

  1. Draw a filled map to the screen
  2. Immediately save the screen to an image
  3. Clear Screen
  4. Draw outline of map
  5. Use saved filled map in ofImage to have boids move around inside the map.

However, it seems like I can’t get the grabScreen to save the image data. I think it is a timing issue where the drawing isn’t happening by the time the grabScreen is called. All of this is running in the draw loop using a boolean flag that is reset when a new map is loaded.

Should I be using an FBO instead? Or is there another method for drawing off screen? I’ve tried to test this quickly but am running into other issues get FBO and malloc errors.

Thanks.


#2

I’ve had mixed results using grabScreen. I would definitely advise using an FBO instead.
Declare an FBO in your header, then every frame in which a change is made to the desired content of the FBO draw everything needed into the FBO, you can then draw the FBO wherever you need to, and then also save it, reuse it, etc etc.
You might be coming into malloc errors if you’re not allocating the FBO first