How to export fbo to SVG?

Hi,

I’m iteratively drawing lines in ofApp::draw() inside an fbo!
What would be a good strategy to export the final drawing to a SVG?
Here’s what I’ve tried so far, but only the background gets exported:

ofBeginSaveScreenAsSVG("test.svg");
fbo.draw(0, 0);
ofEndSaveScreenAsSVG();

Is this even possible?
Thanks.

fbo is raster (pixels) – are you trying to save vector data (with svg)?

you can always do this:

ofPixels p;
fbo.readToPixels§;
ofSaveImage(p, “test.png”);

to save an fbo to an image.

1 Like

Hm, that’s unfortunate… I’d like an SVG for my pen plotter.
Since, you already helped with my previous issue, you may remember that I need fbo for the display/drawing to turn out right, because of the GPU issue.

Could I for instance store geometry objects parallel to the drawing procedure and save those to SVG at the end?
What should I use instead of ofLine(..) , which has been depreciated, to create line objects?
Can I use ‘ofBeginSaveScreenAsSVG(“test.svg”);’ with a C++ vector of line types, or even iteratively, meaning adding line by line during the drawing procedure? Or does this require things to be drawn to work (i.e. ofDrawLine())?

Thanks again, @zach! And thanks for openFrameworks also!! :slight_smile:

Happy to report that I finally came up with a solution myself. :slight_smile:

The problem of the depreciated ofLine(), I solved by creating my own line structure that has its own draw function, where it uses ofDrawLine(). This weirdly enough even solves the GPU issue, where the first few frames were not drawn without the use of FBO.

The SVG export now works with ofBeginSaveScreenAsSVG()and ofEndSaveScreenAsSVG(). What I do is save my line objects in ofApp::update(), once they are created, inside a C++ vector.
In the ofApp::draw() method, I only iterate through that vector and call the draw() method of each line object, which displays the lines. The SVG export can also be triggered here by pressing a key on the keyboard.

Works like a charm!

2 Likes