Resolution-independent graphics with SVG in SDL

Started by
4 comments, last by Michele Fabbri 9 years, 9 months ago

Has anyone used SVG before with SDL, in order to achieve resolution-independent graphics in games? Most of our projects are born in Adobe Illustrator as vector art and we end up exporting a lot of PNG's for different resolutions: iPhone, iPad, Retinas, Droids, Droids HD, etc. I wanted to add some kind of support for SVG in our game, both with preload cache and live rasterization. For example: when a scene loads, i can rasterize the background and props based on the current resolution, but keep the player and enemies being rendered on each frame (since i can alter their SVG in-game).

Do you guys recommend any library with good performance? Is there a SDL integration available, allowing me to render SVG's as SDL textures? I'm on SDL 2.0, by the way.

Advertisement
It's not SDL-centric, but you might look at incorporating NanoSVG with your own custom rasterizer that rasterizes to an SDL image.

But i'll have to save a bitmap from an SVG and then load into SDL? Isn't there a way of doing that in-memory?

Bumping! :)

But i'll have to save a bitmap from an SVG and then load into SDL? Isn't there a way of doing that in-memory?

The example2.c file shows how to get the image into memory. After nsvgRasterize is called img will point to the image data. SDL_CreateRGBSurfaceFrom can be used to create a surface from img. It seems like img will contain 32-bit depth (4 bytes per pixel). So you'd probably call it like this:

surface = SDL_CreateRGBSurfaceFrom(img, w, h, 32, 0, 0, 0, 0);

According to the SDL remarks for that function, when done with surface you would need to call SDL_FreeSurface(surface); and also release the memory pointed to by img. example2.c uses malloc to get the memory so you'd need to use use free(img). If you're using C++ then you should probably allocate the memory with new[] and release with delete[].

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

Has anyone used SVG before with SDL, in order to achieve resolution-independent graphics in games? Most of our projects are born in Adobe Illustrator as vector art and we end up exporting a lot of PNG's for different resolutions: iPhone, iPad, Retinas, Droids, Droids HD, etc. I wanted to add some kind of support for SVG in our game, both with preload cache and live rasterization. For example: when a scene loads, i can rasterize the background and props based on the current resolution, but keep the player and enemies being rendered on each frame (since i can alter their SVG in-game).

Do you guys recommend any library with good performance? Is there a SDL integration available, allowing me to render SVG's as SDL textures? I'm on SDL 2.0, by the way.

At Mazatech we have developed AmanithSVG, a middleware aimed to the static SVG rendering: http://www.mazatech.com/amanithsvg/

We are releasing our SDK as Unity3d plug-in and as Standalone library.

The software is written in pure ANSI C++ and it's crossplatform:

  • Android (ARM, ARMv7, MIPS, X86)
  • iOS7 (Universal Binary)
  • MacOS X (Universal Binary)
  • Windows (X86, X86_64)
  • Linux (ARM, ARMv7, MIPS, PPC, X86, X86_64).

If a closed source solution could fit you requirements, feel free to send me a PM.

Watch the video tutorial (Unity3d plugin version) at: https://vimeo.com/100983415

ScreenShot00.png

ScreenShot01.png

This topic is closed to new replies.

Advertisement