Hi!
Some people asked about SVG support in SFML and i thought it's pretty nice idea. Well, this library actually provides some other features, but it's primary purpose is to draw / rasterize SVG graphics.
Here's what it can do:
- SVG drawing / rasterization;
- Bezier square / cubic curves;
- Some debug features for Bezier curves;
- Bezier curves inherit sf::Shape, so they can be stored in containers like std::vector<sf::Shape*> etc. to manage multiple shapes.
Example code
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Window/Event.hpp>
#include <SFC/Svg.hpp>
int main() {
/* Create image */
sfc::SVGImage img;
/* Don't show debug lines */
img.setMode(sfc::DrawMode::NORMAL);
/* Load SVG image from file */
img.loadFromFile("media/car.svg");
/* Rasterize image & save it to file */
img.rasterize().saveToFile("rasterized.png");
/* Move it by [10, 10] to make it more visible */
img.move({10, 10});
/* Create window */
sf::RenderWindow app(sf::VideoMode((img.getSize().x + 20) * 1, (img.getSize().y + 20) * 1), "sf-svg");
while(app.isOpen()) {
/* Handle events */
for(sf::Event ev; app.pollEvent(ev);) {
if(ev.type == sf::Event::Closed) {
app.close();
}
}
/* Clear window */
app.clear({20, 20, 20});
/* Draw SVG file */
app.draw(img);
/* Display */
app.display();
}
return 0;
}
Result:
http://imgur.com/a/fqUJoAnd here is documentation:
https://koczurekk.github.io/sf-svg///edit: To keep it clear, I use my fork of nanosvg to manage SVG images.