Sign in to follow this  
workaround

SDL2 vector graphics image loader

Recommended Posts

I'm looking for library to load vector graphics into SDL2. I have found cairo which I only find tutorials for sdl1.2. I have also found sdl_svg also sdl1.2 and so on.

 

I can't find any information on loading vector graphic that uses the SDL2. Is the svg file format dead or something.

 

I'm looking for information on loading svg into sdl2?

Share this post


Link to post
Share on other sites

Hi there.

This topic contains a good bit of information about your question.

In shorts: you must obtain some kind of parser/rasterizer library ( such as nanosvg ), integrate it into your project, then use it to load & rasterize SVG image & then pass the results as a pixel data to your SDL_Surface. Then you are free to go with the creation of SDL_Texture or whatever.

Neither SDL1.2 nor SDL2 have direct support for SVG.

 

P.S.

SVG format is a way far from being dead.

Share this post


Link to post
Share on other sites

Has anyone used the nanosvg examples before. I need to install glfw3 on linux. I downloaded to source and compiled it and moved the GLEW directory into the /usr/include. I get errors for all the glfw system calls. I have not used glfw for a while and can't remember what else to do.

 

I just want to get it running with the example before I start making my implementation in SDL.

Edited by workaround

Share this post


Link to post
Share on other sites

Well this is the answer for your problem with compiling examples.

 

 

 

Go to http://www.glfw.org/, download source package.

 

Then go to console and type the following:

unzip glfw-3.1.1.zip
cd glfw-3.1.1/
mkdir curbuild && cd curbuild
cmake -G "Unix Makefiles" -DBUILD_SHARED_LIBS=ON ../
make -j3 
sudo make install

this will place your glfw headers and .so files in appropriate folders under the /usr/local ( you don't have to manually move anything ).

 

Then some part of magic takes effect.

It happened so, that nanosvg has some kind of unhealthy build system inside ( premake4 + pre-made makefiles + damaged ( ??? ) Makefile generated from premake4 ).

To build example do the following.

 

Download nanosvg as .zip from the official github page.

In your console:

 


unzip nanosvg-master.zip
cd nanosvg-master/example
cp ../src/nanosvg* .
gcc -O2 example1.c -L/usr/local/lib -lGL -lglfw -lm -Wl,-rpath=/usr/local/lib -o example1
gcc -O2 example2.c -L/usr/local/lib -lGL -lglfw -lm -Wl,-rpath=/usr/local/lib -o example2

After performing these actions I was able to launch both examples. Good luck to you, and if you need any further explanations ( i.e. makefiles, command line invocations ) feel free to ask.

 

P.S.

I don't know if GLEW is really needed here, cause I have one installed in /usr/local, but it seems that GLFW and nanosvg have no dependencies on GLEW, and I was able to compile, link and run without linking against libGLEW.so.

 

btw, my current system is Linux Mint 17.

Linux host 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2

I have Debian 8 x64 at home, if you need, I can test this there too.

 

Share this post


Link to post
Share on other sites

syskrank thanks for the help on installing glfw and compiling nanosvg.

 

Everything works fine. I'm using Linux mint 17 also with slightly updated kernel and it all worked.

 

I'm sure GLEW is also not needed. I think that I was using GLEW for opneGL to test using depth in my game. I must have typed it by mistake because of that.

Edited by workaround

Share this post


Link to post
Share on other sites

Also because the second example does not display the image there is no need for the glfw linking along with gl. glfw is just a window manager.

gcc -O2 example2.c -L/usr/local/lib -lm -Wl,-rpath=/usr/local/lib -o example2

Share this post


Link to post
Share on other sites


Also because the second example does not display the image there is no need for the glfw linking along with gl. glfw is just a window manager.

Yeah, I know, I've just been lazy hitting 'up' and changing 1s to 2s in gcc command =)

Glad everything worked.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this