SVG Graphics Rendering

Hello(pe)!

I’m fairly new to “systems languages” like Odin and kin (C, C++, etc.) and I decided to try and prototype an application that focuses on manipulating vector graphics. The initial plan was to use Raylib because it had a proc for loading SVGs but when invoking the procedure it spams the following error to stdout:

WARNING: SVG image support not enabled, image can not be loaded

I did some digging and came across a commit to the raylib GitHub that removed SVG support to move it into “raylib-extras” which doesn’t appear to exist in release form as of writing this post. I did more digging into the 5.0 version and found a post on the Odin GitHub asking about the same thing (Raylib SVG Rendering · odin-lang/Odin · Discussion #3809 · GitHub).
I resurrected the discussion with my own findings but nothing has come of it. Given the forum is more easily accessible thanks to being more favorable to search engine indexing I figured I would ask here in hopes of some answer to my questions.

  1. Is there a way to enable SVG support in the bundled version of Raylib without needing to recompile with a config.h file with the appropriate flag?
    1a. If not, is there a module available in core or vender that suits my needs? I looked at nanovg but that looks to be drawing rather than reading files, but I might have misinterpreted.
  2. Is Raylib usable as a “rendering wrapper” for OpenGL or would it be better to use vendor:OpenGL instead?

There’s no way to configure the bundled version of raylib to have different compile flags. You’ll have to recompile raylib yourself and put it into the appropriate directory. It should be possible to compile raylib as a dll, then copy it relative to the .exe’s path and still use the vendor packages, without altering the Odin directory. As for other ways to load svg files, I believe I don’t know any such library in core or vendor packages.

One thing I’ll note though, if your goal is to save and load the vector graphics you have created in your own editor, you should be able to make your own SVG loader in a relatively small amount of time. The svg specification is a good place to start. You can use core:xml for your needs there. As you’ve said you wanted a prototype there’s no need to look too deep into the spec. Just find the features you need and implement only those. You can come back to full support later.

As per graphics backend. It all depends on how deep you want to go. Raylib will obviously suffice for a simple prototype, but if you want something more serious, you’d want to have control over some things, like stroke width, and the way the shape is filled. With that said, you might find transitioning from immediate-style raylib to more serious graphics backends quite hard, because those are very different API’s. If you start with raylib you’d better stick with it. It might be worth implementing it in raylib first, then scrape the whole graphics backend and restart with something like OpenGL or any other graphics API, when you have a better understanding of your problem.

2 Likes

My goal is going to involve a lot of vector graphics loading so I think I’ll look into writing my own SVG loader. I’ve also already put together a bare skeleton OpenGL window based on a gist from GingerBill so I may just continue with that for the prototype.

Thanks for the advise and resources.