a-e-k / canvas_ity

A tiny, single-header <canvas>-like 2D rasterizer for C++
ISC License
342 stars 25 forks source link

SVG support on top of this? #4

Open ensisoft opened 1 year ago

ensisoft commented 1 year ago

Hi,

this is an interesting looking little library. Any idea about the amount of work needed to build an SVG renderer out of this? I work on a game engine and I'm interested in exploring an integration of tiny SVG rendered for scalable resolution independent graphics.

Thanks!

a-e-k commented 1 year ago

Thanks! Both rendering vector assets for games and rendering a subset of SVG are applications that I'd had in mind for this library. In fact, I'd looked into a while back as a potential side project, but didn't want to get too sidetracked from just getting this library to release.

There are few avenues that I can see for this:

  1. Build a little library that directly parses a subset of SVG and makes calls into canvas_ity to do the rendering. Or if you want something already written for this purpose, have a look at NanoSVG. As I understand it, canvas_ity is a much more fully-featured renderer than the one included with NanoSVG and so should make a good back-end for it.

  2. Take a more heavy-weight existing SVG parser and adapt it to flatten the SVG to a series of calls to a canvas-like API which are then serialized. Those then become your cooked assets and you just have a very thin layer that deserializes them and calls canvas_ity. I've had some success at using Inkscape's HTML5 canvas export function to try this for a few SVG files such as the PostScript Tiger. After exporting, I'd load the generated JavaScript into my editor and do regexp search and replaces until I'd turned it into the C++ equivalent that calls canvas_ity. As another potential side project, I've been mulling binary serialized canvas API calls as a lightweight vector image format.

Cheers!

ensisoft commented 1 year ago

Thanks for the answer!

Regarding NanoSVG if there's some kind of glue code that is needed to plug these two together is that a contribution you'd be interested in having in your repo?

a-e-k commented 1 year ago

For now, I'd like to keep this repo fairly slim. But if you do write such glue code and put it in your own repo, I'll be happy to add a link to it on the README here.