Render a vector graphic (.svg) in C++

↘锁芯ラ 提交于 2019-11-30 12:57:42

问题


My and a friend are working on a 2D game where the graphics will be .svg files and we will scale them appropriately either by rasterizing them first, or rendering them directly on a surface (which still would require rasterization at some point).

The problem is, I've been looking all day to find a library that will allow me to take an .svg file and eventually get it to render in allegro. As far as I know, it would involve rasterization into some sort of format that allegro can read and then allegro could render the "flattened" image.

So what are some C++ libraries I could use for taking an .SVG file and "flattening" it so I can render it? The library obviously needs to support scaling too so I can scale the vector graphic then rasterize it.

I'm using Windows and Visual C++ Express 2010.

Any suggestions would be helpful as I am very lost right now:

I've tried Cairo, but it only allows writing of .svg files and doesn't allow you to read the .svg file. I've also looked into librsvg which works with Cario, but I was having a lot of trouble getting it to work properly on Windows (because it has loads of GNOME dependencies). If you have any guides for getting these to work (on Windows) that would be great too.


回答1:


The wxsvg library allows loading and manipulating SVG files. Qt also has an SVG module.




回答2:


I'm coming a little late to the conversation, but I would suggest you to look at Nano SVG, an extremely lightweight svg renderer that doesn't need cairo/libsvg. I got nanosvg compiled and working in a couple of hours. It's very basic, but it gets the job done.




回答3:


SVG++ library provides advanced support for SVG reading, so that rendering SVG with allegro can be implemented in reasonable time.




回答4:


I have recently put together an SVG renderer library in C++: https://github.com/igagis/svgren

It uses Cairo for rendering to off-screen surface. Supports gradients and all kind of shapes.




回答5:


Personally, I using NanoSVG in my Simple Viewer GL. It's allowing me easy to load and rasterize SVG images in few lines of code. But this library has weak SVG support.



来源:https://stackoverflow.com/questions/4176637/render-a-vector-graphic-svg-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!