SFML community forums

General => SFML projects => Topic started by: korczurekk on December 10, 2016, 08:17:17 pm

Title: SF-SVG, simple SVG-XML library
Post by: korczurekk on December 10, 2016, 08:17:17 pm
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:

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/fqUJo (http://imgur.com/a/fqUJo)

And here is documentation: https://koczurekk.github.io/sf-svg/

//edit: To keep it clear, I use my fork of nanosvg to manage SVG images.
Title: Re: SF-SVG, simple SVG-XML library
Post by: eugustus on December 29, 2016, 01:04:29 am
Nice. If I can load this as texture to OpenGL? I can try on future.

Sory for bad english...
Title: Re: SF-SVG, simple SVG-XML library
Post by: roccio on December 29, 2016, 04:17:26 pm
I have tryied this and it seems a good implementation. Just one question. The rasterizer works very well, I can see the image in ull colors, but if I draw the svg I can only see lines. Is there a way to draw the svg with all it's colours?
Title: Re: SF-SVG, simple SVG-XML library
Post by: korczurekk on January 05, 2017, 03:43:16 pm
Nice. If I can load this as texture to OpenGL? I can try on future.
I don't really know, I'm not 'that OpenGL guy'. But you can convert it to image and then to sf::Texture, is it good?

I have tryied this and it seems a good implementation. Just one question. The rasterizer works very well, I can see the image in ull colors, but if I draw the svg I can only see lines. Is there a way to draw the svg with all it's colours?
You have to create texture from rasterized image and then attach to sprite etc.
Title: Re: SF-SVG, simple SVG-XML library
Post by: eugustus on January 07, 2017, 09:24:32 am
I don't really know, I'm not 'that OpenGL guy'. But you can convert it to image and then to sf::Texture, is it good?

Very :-)