Drawing into an ofTexture

I’ve been using OF for a while now, but I’ve never had this need before.

Load an ofImage from file, and try to draw some shapes / stuff on top of the image, using the GPU, not modifying the individual pixels.

The way I would go at it would be to create an ofFbo the same widthheight as the ofTexture, draw the ofTexture in it, draw the other stuff on top, and convert back to ofImage and save.

// code not tested
ofImage image ("test.png");
ofFbo fbo;
fbo.allocate(image.getWidth(), image.getHeight());
    // draw more stuff
ofImage save;

Are there other ways of doing this, more efficient etc?


That’s the most straightforward way. The bottlenecks are typically in glReadPixels. You can look at addons like this

which I believe uses Pixel Buffer Objects (PBOs) which is a more modern/faster alternative to glReadPixels

another bottleneck is encoding to png, jpg or whatever the format. encoding to tga might take shorter but being bigger the time to store it becomes the bottleneck.

i recently did an addon that downloads the texture using a pbo on a different thread and then uses several cores to encode several images at the same time before saving: https://github.com/arturoc/ofxTextureRecorder.

it will only work with the current master or nightly builds though

1 Like