12

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.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Brad
  • 10,015
  • 17
  • 54
  • 77

8 Answers8

10

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

Community
  • 1
  • 1
Vijay Mathew
  • 26,737
  • 4
  • 62
  • 93
  • wxSVG looks perfect because I have experience with wxWidgets. Although I have absolutely no idea how to compile on Windows, I'll figure it out eventually. Thanks :) – Brad Nov 14 '10 at 08:18
  • 4
    Update for this answer: the wxSVG project has moved to a different page. http://wxsvg.sourceforge.net/ – Marleen Schilt Jun 27 '18 at 08:06
6

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.

Jaime Ivan Cervantes
  • 3,579
  • 1
  • 40
  • 38
3

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

Samuel
  • 31
  • 1
2

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

OlegMax
  • 325
  • 2
  • 8
2

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

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

igagis
  • 1,959
  • 1
  • 17
  • 27
  • Have you used this library for rendering text? I am having problems with text. – Subhamoy S. Apr 27 '17 at 07:33
  • @SubhamoySengupta please submit an issue to https://github.com/igagis/svgren/issues if you have any problems with the library – igagis Apr 27 '17 at 09:14
  • 3
    I would submit an issue if I found a bug. Since it looks like text is not supported at all, I am not sure if it would be an issue. Hence the question. – Subhamoy S. Apr 28 '17 at 10:54
  • @SubhamoySengupta bugs, issues, feature requests, questions - all go to github.com/igagis/svgren/issues, no matter that it is called 'issue' on github. Although, you are right, text is not supported and it is unlikely it will be supported ever. But, there can be workarounds, for example, most SVG editors allow converting text to paths, that would make text rendered into the raster image. If any more questions, please use github issue tracker for those. – igagis Apr 28 '17 at 11:35
1

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.

1

With the help of nanosvg and many other c++ svg parsers, adding svg rendering capability to your application should be trivial. The recipe is as follows: svg parser + vector rendering library = trivial svg rendering. The vector rendering library can be cairo and a number of other libraries (nanovg comes to mind, as well as a number of other vg libraries). Here's an example of how to support svg rendering with cairo + fltk + nanosvg combo. Now, all the svg parsers, as well as cairo itself, along with other renderers, have bugs/shortcomings, but basic svg support should never present a problem.

user1095108
  • 14,119
  • 9
  • 58
  • 116
0

I was looking for a real quick way to render SVG file in a Windows OS based MFC project.

In that case, Microsoft Browser Web Browser ActiveX Control is found to be an ideal solution.

enter image description here

And here is the result of loading SVG file using the Browser control.

Rendering SVG file using a Browser Control

MNS
  • 1,354
  • 15
  • 26