Is it possible to add SVG support to the engine?
Moderator: Moderators
Is it possible to add SVG support to the engine?
SVG is an open specification for Scalable Vector Graphics. It is quickly becoming a standard in interface design, mainly because it is entirely scalable (you could probably guess that from the name).
For us poor LuaUI developers, in-engine SVG support would be a major improvement over the current PNG system. The problem is that in creating scalable windows (a requirement for any good UI), raster graphics look horrible unless they are presented at their exact original size. This pretty much means that it is impossible to arbitrarily scale the UI and make it look good at the same time.
SVG would fix this problem. I'm not asking for full-fledged animated SVG support, I'm just asking the devs to come up with a lua interface for loading, scaling, and displaying SVG graphics. There are several open-source libraries that can make this task much easier, librsvg being a good example.
What I'm wondering is if this is a reasonable request, and when/if it could be implemented.
http://librsvg.sourceforge.net/
For us poor LuaUI developers, in-engine SVG support would be a major improvement over the current PNG system. The problem is that in creating scalable windows (a requirement for any good UI), raster graphics look horrible unless they are presented at their exact original size. This pretty much means that it is impossible to arbitrarily scale the UI and make it look good at the same time.
SVG would fix this problem. I'm not asking for full-fledged animated SVG support, I'm just asking the devs to come up with a lua interface for loading, scaling, and displaying SVG graphics. There are several open-source libraries that can make this task much easier, librsvg being a good example.
What I'm wondering is if this is a reasonable request, and when/if it could be implemented.
http://librsvg.sourceforge.net/
I guess it is one of those additionnal features that, while being interesting, isn't like high priority really needed, and that no current dev got interested enough in, which mean it'll never get implemented unless you code it yourself. AFAIK Spring use the devil library for all its image needs, so you have to ask them, or code for them, SVG support. But from what I gather, since SVG is vectorial and not raster, I guess coding svg support isn't as easy. Though you provided a link to a libary. Hmm, wouldn't svg be too slow for real time game? I mean, interpreting all those commands and recreating the picture by drawing curves & lines must be slower than dumping a large block of pixels, no? Well, I don't really know, but I thought more replies would make you happier.AlfaSub wrote:No one is willing to comment on this? At all?

- clericvash
- Posts: 1394
- Joined: 05 Oct 2004, 01:05
While doing it real-time like this would probably be wasteful, painting the SVG panel to a raster in memory and storing it, and only updating the memory raster when needed could get around this easily. This way it would be just as efficient as normal raster images, and only lag minimally when resizing/repainting the GUI windows.zwzsg wrote:Hmm, wouldn't svg be too slow for real time game? I mean, interpreting all those commands and recreating the picture by drawing curves & lines must be slower than dumping a large block of pixels, no? Well, I don't really know, but I thought more replies would make you happier.
I just had a look at the Spring source and librsvg, and would it be do-able by doing something like the following?
I believe it would then just work with the LuaUI function "DrawTexture", except you'd call it something like
- Modify CGuiHandler::BindNamedTexture (in rts\game\UI\GuiHandler.cpp) so that somewhere near the top after it checks to see if the requested texture already exists, add some checks for an "SVG" qualifier in the file name along with one for width and one for height.
- If the SVG qualifier exists, immediately after the code delcares "CBitmap bitmap;", rather than load the bitmap image, use librsvg to load the SVG file, and then convert the output GdkPixbuf object to the CBitmap bitmap object, and then let the rest of the function put it into OpenGL for you.
I believe it would then just work with the LuaUI function "DrawTexture", except you'd call it something like
Code: Select all
DrawTexture(":S,100,100:thomasTheTankEngine.svg")
If I were to add SVG loading capability, then I'd add a separate
command to draw the SVG into a texture.
local svgTex = gl.MakeSVGTexture(..., string SVGData)
Note that that would allow you to write you own SVG's with lua.
This might come in handy for changing little things like the team
colors, etc... (p.s. the unsynced sides of LuaCob/Gaia/Rules can
not write files)
As it is, you could implement your own raster graphics in raw GL.
I've yet to see anyone (other than myself), try using a model to
render a UI element. This request goes fairly low on my todo list.
command to draw the SVG into a texture.
local svgTex = gl.MakeSVGTexture(..., string SVGData)
Note that that would allow you to write you own SVG's with lua.
This might come in handy for changing little things like the team
colors, etc... (p.s. the unsynced sides of LuaCob/Gaia/Rules can
not write files)
As it is, you could implement your own raster graphics in raw GL.
I've yet to see anyone (other than myself), try using a model to
render a UI element. This request goes fairly low on my todo list.
Was anyone looking into this?
I had more of a look at librsvg and found that it seems to have more dependencies than I initially thought (like gtk). There was also SDL_svg (two different versions out there) and antigrain, which has some basic SVG abilities - see http://www.antigrain.com/svg/index.html for an example.
Just to see if it was possible, I had a go at implementing antigrain into the CGuiHandler::BindNamedTexture function as I'd detailed above. Trepan's suggestion seemed a much better approach, but I just wanted to do it with minimum editing of Spring files. My initial efforts worked and I was able to display an svg image from LuaUI.
Here I changed the eyes widget to display tux.svg (original is here):

(ironically I've only tried this code under Windows with Mingw)
Would the dev's like this code? Antigrain's svg rendering is a bit limited as it can't do gradients (or a few other things), although the library itself handles gradients wonderfully so it may be possible to add. With a little more work I should be able to expand it to include Trepan's suggested "MakeSVGTexture" LuaUI function. I still need to add an option to scale the svg image before its rendered to the bitmap, but that shouldn't be much.

I believe that all but the two buttons labeled "button" are done without images.
I had more of a look at librsvg and found that it seems to have more dependencies than I initially thought (like gtk). There was also SDL_svg (two different versions out there) and antigrain, which has some basic SVG abilities - see http://www.antigrain.com/svg/index.html for an example.
Just to see if it was possible, I had a go at implementing antigrain into the CGuiHandler::BindNamedTexture function as I'd detailed above. Trepan's suggestion seemed a much better approach, but I just wanted to do it with minimum editing of Spring files. My initial efforts worked and I was able to display an svg image from LuaUI.
Here I changed the eyes widget to display tux.svg (original is here):

(ironically I've only tried this code under Windows with Mingw)
Would the dev's like this code? Antigrain's svg rendering is a bit limited as it can't do gradients (or a few other things), although the library itself handles gradients wonderfully so it may be possible to add. With a little more work I should be able to expand it to include Trepan's suggested "MakeSVGTexture" LuaUI function. I still need to add an option to scale the svg image before its rendered to the bitmap, but that shouldn't be much.
This is quite a good point. The 2d Clanlib library uses OpenGL to render all of it's gui. An example from their site:trepan wrote:As it is, you could implement your own raster graphics in raw GL. I've yet to see anyone (other than myself), try using a model to render a UI element. This request goes fairly low on my todo list.

I believe that all but the two buttons labeled "button" are done without images.