Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying SVG in OpenGL without intermediate raster

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 ?

like image 1000
timday Avatar asked Jun 22 '09 13:06

timday


4 Answers

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.

like image 54
shoosh Avatar answered Oct 02 '22 14:10

shoosh


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

like image 45
danio Avatar answered Oct 02 '22 14:10

danio


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.

like image 2
SpliFF Avatar answered Oct 02 '22 14:10

SpliFF


My answer is going to about displaying vector graphics wtih OpenGL in general, because all solutions for this problem can support rather trivially SVG in particular, although none support animated SVGs (SMIL). Since there was nothing said about animation, I assume the question implied static SVGs only.

Since 2011, the state of the art is Mark Kilgard's baby, NV_path_rendering, which is currently only a vendor (Nvidia) extension as you might have guessed already from its name. There are a lot of materials on that:

  • https://developer.nvidia.com/nv-path-rendering Nvidia hub, but some material on the landing page is not the most up-to-date
  • http://developer.download.nvidia.com/devzone/devcenter/gamegraphics/files/opengl/gpupathrender.pdf Siggraph 2012 paper
  • http://on-demand.gputechconf.com/gtc/2014/presentations/S4810-accelerating-vector-graphics-mobile-web.pdf GTC 2014 presentation
  • http://www.opengl.org/registry/specs/NV/path_rendering.txt official extension doc

You can of course load SVGs and such https://www.youtube.com/watch?v=bCrohG6PJQE. They also support the PostScript syntax for paths. You can also mix path rendering with other OpenGL (3D) stuff, as demoed at:

  • https://www.youtube.com/watch?v=FVYl4o1rgIs
  • https://www.youtube.com/watch?v=yZBXGLlmg2U

NV_path_rendering is now used by Google's Skia library behind the scenes, when available. (Nvidia contributed the code in late 2013 and 2014.) One of the cairo devs (who is an Intel employee as well) seems to like it too http://lists.cairographics.org/archives/cairo/2013-March/024134.html, although I'm not [yet] aware of any concrete efforts for cairo to use NV_path_rendering.

An upstart having even less (or downright no) vendor support or academic glitz is NanoVG, which is currently developed and maintained. (https://github.com/memononen/nanovg) Given the number of 2D libraries over OpenGL that have come and gone over time, you're taking a big bet using something not supported by a major vendor, in my humble opinion.

like image 2
Fizz Avatar answered Oct 02 '22 15:10

Fizz