Svg rendering
nifker

I would like to know if allegro can render svgs or if support for such a renderer is planned?

amarillion

Full SVG is very big. It's not part of Allegro and as far as I know there are no plans in that direction.

But perhaps a subset of SVG would not be hard to implement. So I want to ask a question as well: What would be the best strategy to render arbitrary paths and gradients in Allegro?

nifker

I mean using another library to render it in allegro.

Chris Katko

However, there's no reason someone couldn't write a SVG renderer addon for Allegro. Or even port/wrap a popular one like librsvg. There are very many C/C++ ones out there that vary from subset to full SVG implementations.

I may work on a subset implementation at some point. (But don't hold your breathe!)

Didn't Aaron Bolyard write a game prototype that uses vector graphics with Allegro? Did he implement SVG with it?

[edit]

This one:

http://svgpp.org/

Is a C++ header only one. It includes a c++ demo app that renders to raster image. One could adapt a wrapper from there.

If you're looking for "has someone already done all the work" though, except for possibly Aaron Bolyard, I don't think that exists yet.

Aaron Bolyard

Didn't Aaron Bolyard write a game prototype that uses vector graphics with Allegro? Did he implement SVG with it?

I made a proof-of-concept hardware-accelerated, real-time vector graphics library. Technically the graphics stuff is API agnostic, but I only had an OpenGL backend. Allegro was used to handle creating the OpenGL display, timing, and handling the input. It's not easily usable outside of the demos I made.

Support for SVG would just require translating SVGisms to the canvas-like API. I hacked together a tool to convert SVG to a really basic XML format that only supported groups/paths and a solid fill style with a very narrow path command.

I never went forward because of the anti-lottery known as patents. A patent--essentially a method to solve an inequality using the GPU--owned by Microsoft was very necessary for performance reasons. But I may have found another way of rendering resolution-independent quadratic curves after coming across research from someone with a similar problem. In honesty, I think it's possible to move forward without infringing any patents now so that's what I've been doing...

Regarding OP, I would suggest rendering SVGs to a raster format, like PNG. If quality at different magnifications is a concern, you could create multiple levels of detail and use them appropriately. It's counter-productive to rasterize the graphics at runtime--loading times will be much slower and you don't have the benefit of real-time vector graphics.

Chris Katko

Regarding OP, I would suggest rendering SVGs to a raster format, like PNG.

Yeah, it depends on how much of SVG's uniqueness is really needed. Is it just an easy development format? Then "bake" the SVG's at whatever (few) resolutions are needed. It's going to end up as pixels at some point.

Is scaling needed? Rasturized may still work depending on the scale ranges.

Is animation needed? Animate the individual parts, or, implement a proper SVG renderer based on an existing library or sample code.

Elias

Google decided SVG is too complex so their Android libraries support only a subset of SVG called "vector drawables". If someone wants to write a renderer from scratch that would probably be a better format to start with. Google's vector drawable renderer is open source but not sure if anyone ported it to be usable outside of Android.

SiegeLord

You can use cairo and render your SVG to an ALLEGRO_BITMAP, and then draw that. You could follow this example here: https://www.cairographics.org/SDL/, except for Allegro you'd use al_lock_bitmap and ALLEGRO_LOCKDED_REGION (which has the pitch value you need).

David Couzelis

Android Vector Drawables reminds me of the Haiku Vector Icon Format[1]. SVG was too big, so the Haiku developers created their own format.

[1] https://en.wikipedia.org/wiki/Haiku_Vector_Icon_Format

Aaron Bolyard
Elias said:

Google decided SVG is too complex

and

SVG was too big, so the Haiku developers created their own format.

Definitely. SVG is to vector graphics as HTML is to textual documents...

Thread #616251. Printed from Allegro.cc