Page 1 of 1
Is it possible to add SVG support to the engine?
Posted: 12 Jun 2007, 01:45
by AlfaSub
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/
Posted: 17 Jun 2007, 21:50
by AlfaSub
No one is willing to comment on this? At all?
It might not be as interesting as some of the other proposed gameplay features, but it would make interface development a lot easier. I thought at least trepan would comment on this.
Posted: 17 Jun 2007, 22:44
by Argh
Um, well, couldn't we just develop a method detecting what rez people are using, and use the bitmaps for that size or smaller, instead? That's what most games do.
Posted: 18 Jun 2007, 09:07
by Maelstrom
SVG makes a lot more sense though. Its very design makes it perfect for this application. I dont have the skills to do it myself, but +10 to this idea.
Posted: 18 Jun 2007, 10:38
by Tobi
To answer the OP's question, it is a reasonable request, but I can not promise it will be implemented anytime soon / at all.
Posted: 18 Jun 2007, 10:55
by zwzsg
AlfaSub wrote:No one is willing to comment on this? At all?

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.

Posted: 18 Jun 2007, 14:26
by clericvash
To be honest i thought it would be a needed feature, detecting resolution and sizing png's, no thanks!
Posted: 18 Jun 2007, 15:18
by Maelstrom
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.

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.
Posted: 18 Jun 2007, 15:18
by jcnossen
Its a great idea obviously, but there are a lot of great ideas and few/no people that want to implement them.
Maybe if you request a lua SVG binding trepan will make it

(j/k)
Posted: 18 Jun 2007, 18:06
by Neddie
I actually like this idea.
Posted: 19 Jun 2007, 04:58
by tinnut
I just had a look at the Spring source and librsvg, and would it be do-able by doing something like the following?
- 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.
Would this work? Pending any #include or linking problems to librsvg, it
might be straight forward, maybe even easy?..
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")
Posted: 19 Jun 2007, 05:29
by trepan
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.
Posted: 21 Jun 2007, 12:18
by tinnut
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.
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.
This is quite a good point. The 2d
Clanlib library uses OpenGL to render all of it's gui. An example from their site:

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