views:

531

answers:

3

Making my Asteroids clone (in C) I've rather fallen in love with vector-based entities, but I've simply coded them in as x,y-point arrays. That's been fine for something like Asteroids, but what should I do if I want to make more complex 2D models?

I note that there is an awful lot of 3D modelling software out there, as well as ample tutorials and help on importing 3D models into one's C/C++ program for use with Open GL.

However I'm rather more interested in creating 2D vector-based models than 3D, as I'm perfectly happy to keep trying 2D games for a while yet. Does such a concept as 2D modelling exist? Are there tools for creating and exporting 2D models and libraries for importing 2D models specifically, or does one just create flat models in 3D software and then import those files (e.g. .3ds, .ms3d) and lay them flat onto the z-axis?

My only thought so far was perhaps using something like Inkscape for modelling, generate SVG files, and then use Cairo to import and render them. Will that work well, or do you have other recommendations?

Note I'm a bit of a newbie to modelling of any kind, so I may be asking a silly question...

+7  A: 

As far as 2D vector game programming goes, it usually is the domain of Flash and Flex.

Still SVG and loading it via Cairo seems to be a viable solution. Although I'd take care to make sure that you have hardware acceleration enabled (OpenGL backend preferably).

As far as 2D formats go, you won't get as good support as for SVG for any format, so I'd stick with it. Technically things like Collada or X3D do support 2D graphics, but practically they have a lot of useless (for a 2D programmer) bloat.

Kornel Kisielewicz
+1 for flash and flex
BlueRaja - Danny Pflughoeft
+3  A: 

SVG is the way to go for 2D :)

If drawing speed is an issue, you'll have to be careful about how complicated your files get though - and note that SVG isn't optimised for speed of parsing either, so you might incur a significant start-up time penalty while you load your models.

Autopulated
+1: startup time isn't such an issue, more important it is to keep the format in the program in a way that allows for fast hardware rendering .
Kornel Kisielewicz
+2  A: 

No need to upvote my own answer, but I've done a bit more research into using SVG. As I'm using OpenGL, it seems that OpenVG might be a good match.

  • AmanithVG - a commercial implementation of OpenVG built on OpenGL, with both software and hardware rendering. Download available for evaluation only, and it works beautifully, though I don't know how much it costs.
  • ShivaVG - the author was annoyed that AmanithVG was commercial, so made his own opensource implementation in pure ANSI C. Hasn't been updated for a while though. At SourceForge.
  • Anti-Grain Geometry - not sure about this one. I think there is support for SVG, but I think software-rendering only.
  • librsvg - uses Cairo as a primary backend to render SVGs. Looks good.

It seems that all except librsvg stop short of actually allowing SVG files to be loaded in, so presumably there needs to be another step where SVGs are parsed into appropriate OpenVG structures (which mostly seem to be big float arrays, so not too hard). There likewise seems to be a one-to-one mapping of items from SVG to OpenVG, which is promising. As far as I can tell, OpenVG was pretty much made for SVGs.

I will probably use ShivaVG. Maybe it's not perfect, but it draws the tiger and I love a pure C / OpenGL implementation, and I seriously doubt I'll be doing anything all that complex just yet.

Gavin Schultz-Ohkubo