Is it possible to add SVG support to the engine?

Is it possible to add SVG support to the engine?

Requests for features in the spring code.

Moderator: Moderators

Post Reply
User avatar
AlfaSub
Posts: 17
Joined: 07 Feb 2006, 20:28

Is it possible to add SVG support to the engine?

Post 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/
User avatar
AlfaSub
Posts: 17
Joined: 07 Feb 2006, 20:28

Post by AlfaSub »

No one is willing to comment on this? At all? :cry:

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.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post 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.
User avatar
Maelstrom
Posts: 1950
Joined: 23 Jul 2005, 14:52

Post 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.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post 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.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Post by zwzsg »

AlfaSub wrote:No one is willing to comment on this? At all? :cry:
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. ;)
User avatar
clericvash
Posts: 1394
Joined: 05 Oct 2004, 01:05

Post by clericvash »

To be honest i thought it would be a needed feature, detecting resolution and sizing png's, no thanks!
User avatar
Maelstrom
Posts: 1950
Joined: 23 Jul 2005, 14:52

Post 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.
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post 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)
User avatar
Neddie
Community Lead
Posts: 9406
Joined: 10 Apr 2006, 05:05

Post by Neddie »

I actually like this idea.
tinnut
Posts: 67
Joined: 09 Sep 2006, 08:17

Post 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")
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post 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.
tinnut
Posts: 67
Joined: 09 Sep 2006, 08:17

Post 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):
Image
(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:
Image
I believe that all but the two buttons labeled "button" are done without images.
Post Reply

Return to “Feature Requests”