Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Svg rendering

This thread is locked; no one can reply to it. rss feed Print
Svg rendering
nifker
Member #16,327
May 2016

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

amarillion
Member #940
January 2001
avatar

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?

--
Martijn van Iersel | My Blog | Sin & Cos | Tegel tilemap editor | TINS 2017

nifker
Member #16,327
May 2016

I mean using another library to render it in allegro.

Chris Katko
Member #1,881
January 2002
avatar

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.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs

Aaron Bolyard
Member #7,537
July 2006
avatar

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
Member #1,881
January 2002
avatar

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.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs

Elias
Member #358
May 2000

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.

--
"Either help out or stop whining" - Evert

SiegeLord
Member #7,827
October 2006
avatar

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).

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

David Couzelis
Member #10,079
August 2008
avatar

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
Member #7,537
July 2006
avatar

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...

Go to: