Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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.

like image 748
Brad Avatar asked Nov 14 '10 07:11

Brad


People also ask

How do I render an SVG file?

The easiest way to render SVG files is to construct a QSvgWidget and load an SVG file using one of the QSvgWidget::load() functions. QSvgRenderer is the class responsible for rendering SVG files for QSvgWidget, and it can be used directly to provide SVG support for custom widgets.

How are vector graphics rendered?

Vector images and objects may be twisted, stretched and colored using mathematical operators in the software and rendered to the user through a graphical user interface (GUI). Transformations can also include set operations on closed shapes. Vector formats are ideal for drawings that are device independent.

How is SVG rendered?

SVG uses a "painters model" of rendering. Paint is applied in successive operations to the output device such that each operation paints onto some area of the output device, possibly obscuring paint that has previously been layed down.

Does SVG support vector graphics?

SVG is an XML language, similar to XHTML, which can be used to draw vector graphics, such as the one shown below. It can be used to create an image either by specifying all the lines and shapes necessary, by modifying already existing raster images, or by a combination of both.


3 Answers

https://github.com/sammycage/lunasvg is a nice svg parsing, rendering and manipulating library. It is written with pure c++

like image 123
Samuel Avatar answered Nov 06 '22 14:11

Samuel


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.

like image 43
Jaime Ivan Cervantes Avatar answered Nov 06 '22 16:11

Jaime Ivan Cervantes


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

like image 10
Vijay Mathew Avatar answered Nov 06 '22 16:11

Vijay Mathew