[SDL] Best approach to Rendering Vector Graphics with SDL?

Jonathan Dearborn grimfang4 at gmail.com
Wed Mar 13 06:10:48 PDT 2013


It's important to note that you shouldn't expect "vector graphics" to be a
magical solution and that it means different things depending on the
context.

First off, no matter what you do, vector graphics must be rasterized at
some point (unless you use a specialized display).  For the best
performance, you want this rasterization to happen on the GPU.  There isn't
really a widely accepted solution for rendering vector graphics on the GPU.
 Hopefully OpenVG will get wider adoption so we can depend on it.  Some
hardware vendors are trying, but it's far from common.  Cairo is a software
solution (also has an OpenGL backend which might be worth looking at).

Next, when someone says "vector graphics", they might actually mean "vector
art".  Vector art is used in a lot of games (Aquaria is one of my favorite
examples), almost never with an actual runtime vector graphics rendering
pipeline.  You can create a nice-looking graphic in Inkscape (which I
highly recommend), save it to a high-res png, then use it in your game.  As
long as you're using a hardware-accelerated backend (like OpenGL), it's
going to perform much better than parsing an SVG file and going through all
of the rasterization steps at runtime and you an do all the rotation and
scaling you want.  Also, vector graphics usually look simpler than raster
graphics for good reason.  If you want complex details in your visuals,
then it will probably not work well (computationally, or your time effort
to put those details in).  It's good for a few specific art styles and
techniques.

Lastly, the actual work you have to do for achieving resolution
independence with raster graphics vs. vector graphics is about the same.
 You have to define the drawing region and calculate the scaling (and
possibly positioning) and everything either way.  The real differences are
that you're going to save memory using vector graphics (usually only
important for low-resolution mobile devices, but remember that the
computational cost is higher) and you'll get better quality at high
resolution for the same low memory cost.  Depending on your art tools, you
can usually export appropriately-sized raster images for the display
resolutions that you are targeting and be just fine.

In my opinion, it's best not to spend your time trying to work out how to
use vector graphics at runtime unless the lower memory needs of vector
formats is important (as it is for browsers since download speeds are a
bottleneck).  Wait until the hardware support has improved before going
down that path.  Do definitely use Inkscape to create vector art assets and
use them in your hardware-accelerated games.

Jonny D



On Wed, Mar 13, 2013 at 7:21 AM, LM <lmemsm at gmail.com> wrote:

> bazz wrote:
> >1. What is so great about vector art?
>
> Supposedly faster more efficient downloads for browsers (if you're
> displaying via the web).  However, not all browsers support it.  As to
> vector formats, IE used VML for a long time.  It's finally switching
> to the W3C standard.  W3C promotes SVG.  Xfig format has been around
> for a long time (longer than SVG) and is mainly used by applications
> on a system.  Haven't seen much if any web use of Xfig format.
>
> >2. How come I can't find anything on Displaying Vector Art with SDL??
> >- - Something as useful as this sounds to be begging for association with
> SDL.... I mean ya I
> >found some screwy libSVG library from 2008 or so.. but something so
> outdated I will prefer to
> >stay away from. I am hoping for better answers/advice.
>
> I thought the SDL_svg library ( http://www.linuxmotors.com/SDL_svg/ )
> looked promising.  I'm not particular about whether something's
> currently supported or not.  Most Open Source programs I've run across
> use libRSVG.  (Here's a note about it with Tux Paint:
>
> http://forums.libsdl.org/viewtopic.php?t=4968&sid=a6a67aec3d184e5d522f35c9f1d3b513
> )
>  I wasn't particularly thrilled with this approach because it brings
> in a lot of dependencies which I'm not otherwise using on my system.
> You could look into xfig/winfig, transfig, netpbm options and store
> graphics in vector format for space concerns, but convert to bitmap
> before drawing.
>
> One other link I thought was interesting:
> http://code.google.com/p/svg-edit/
> It's a SVG editor in a browser.
>
> Speaking of browsers, netsurf is a lightweight browser that supports,
> among other things, SDL display.  You may want to check out how
> they're adding SVG support to their browser:
> http://www.netsurf-browser.org/projects/libsvgtiny/
> It's an active project if that's what you're looking for.
>
> > I don't know much about vector graphic file formats. The benefits behind
> each one, or why cell phones are using a different SVG format, i think it's
> called tiny SVG?? (not sure, time is short)
>
> Phones are using a subset of SVG (partly for speed and partly for
> compatibility).  It's basically the same format, just not all the
> features.
>
> >This is still rough in the dome. So I am really looking for answers. Can
> anyone help me out? >Once again, I'm just trying to open up this treasure
> chest of universal screen support
>
> Hopefully, I've given you a few ideas.  Would be interested to hear if
> you turn up any other useful resources for vector graphics.
>
> Sincerely,
> Laura
> http://www.distasis.com/cpp
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20130313/c72799d8/attachment-0009.htm>


More information about the SDL mailing list