views:

2787

answers:

5

I have some simple SVG artwork (icon and glyph kind of things) which I want to display in an OpenGL app (developing in C++ on Debian, using Qt).

The obvious solution is to use the ImageMagick libs to convert the SVGs to raster images and texture map them onto some suitable polygons (or just use good old glDrawPixels).

However, I'm wondering if there's anything out there which will translate the SVG directly to a sequence of OpenGL calls and render it using OpenGL's lines, polygons and the like. Anyone know of anything which can do this ?

+4  A: 

Qt can do this.
QSvgRenderer can take an SVG and paint it over a QGLWidget
Its possibly you'll need to fiddle around with the paintEvent() abit if you want to draw anything else on the QGLWidget other than the SVG.

shoosh
Thanks, very interesting (should have noticed that one myself). It's unclear to me from the documentation whether the vector aspect would be preserved completely in QPainter-on-QGLWidget or whether some intermediate rasterization happens. Ought to be easy enough to find out using GLintercept/GLtrace though...
timday
QPainter doesn't usually do any rasterization. There's no reason for it to start doing it in the case of SVG.
shoosh
timday
I'd send a feature request for that using the bug report web form anyway.
shoosh
I also note that enabling automatic multisampling in the Nvidia drivers also makes the SVG graphics look very nice and antialiased (which wouldn't happen if Qt was just blitting some software-rendered bitmap).
timday
+3  A: 

SVGL appears to address this but has been dormant for several years. Still you might be able to find some code of value there.

danio
The "sauvage" project mentioned by "dru" below appears to be the successor. Same author, but python rather than C++.
timday
+2  A: 

It looks like Inkscape has some interesting export options you may find useful. They include DXF, PovRay, EPS, PS (PostScript), XAML, Latex and OpenDocument Drawing (ODG). Perhaps there is a converter for one of those and you could use Inkscape as an intermediary.

DXF in particular is a likely candidate since it is a common 3D format already. assimp is a good candidate for loading DXF.

SpliFF
Inkscape doesn't have yet a full implementation of SVG so I would imagine that its export options are also partial.
shoosh
Well actually all the SVG I'm using is created in Inkscape anyway, so as long as it can export all it's own stuff... no problem.
timday
You're going to more limited by the output format than SVG anyway. DXF is like a million years old, it isn't going to support crop marks or complex gradients.
SpliFF
+3  A: 

http://lii-enac.fr/~conversy/research/sauvage/index.html

dru
This seems the closest to what I originally had in mind. The pythonness of it might not actually be a problem as I'm toying with doing the app front-end using PyQt4 rather than pure C++.
timday
+1  A: 

there's also tkzinc as a possibility

chris