DEV Community

Beau
Beau

Posted on • Updated on

Nyx: 3rd party libraries

Don't reinvent the wheel

This is already a somewhat hypocritical statement as I've already mentioned that there are many existing libraries that are great for graphics in C++, but it really is true in most cases.

Do not reinvent the wheel, you will likely do it worse than those who came before you.

Obviously I have some level of hubris here in that I think I can do better than what's out there, but that's okay! What I'm referring to here is that it's okay to take advantage of the work of others (with permission, of course), especially when you're doing something as complicated as a whole framework. There are many things that I do not want to write myself, and I have employed libraries where appropriate.

SDL2 [link]

As much as I was talking down to SDL2, it actually makes a great windowing library. I won't use anything out of it that actually draws things onto the screen, but it's great for creating a window and getting an OpenGL context ready. The event handling is also pretty good--it's a very C-ish idiom, but polling events to me is way nicer than using callbacks--and it'll even enable me to add gamepad support in the future if I really want to.

Glad [link]

You have to have an OpenGL context open to do anything, and that's where Glad comes in. For those unaware, OpenGL has two major profiles, compatibility and core. The compatibility profile is deprecated since 2008/9 and should not be used, but is there so old software doesn't break. Unfortunately, when we make an OpenGL context, it only actually loads compatibility functions, so we need an OpenGL loader to load the new things for us. That's where Glad comes in, it loads those functions after we've created our context. There are a lot of loaders, none of them are really good or bad, they just sort of are. The one thing I don't like about Glad is that I don't know how to use it with CMake, but I wrote a script to update dependencies like Glad that don't work with the rest of my system.

ImGui [link]

ImGui is definitely more a nicety than a necessity, but it'll allow for adding in text onto the screen before I'm able to draw it with the library. It's great for quick tests if you want to be able to interact with what you've made, and I'd highly recommend it.

{fmt} [link]

fmt is the definition of extraneous, but it's so nice that I can't not use it. It's an I/O library that is actually an implementation of things that are going to be added into C++20. C++20 is a bit too new for me to feel comfortable putting my project on it yet, but using fmt for now is much nicer than the fresh hell that is iostream.

fmt::print("Isn't this nice?\n");
Enter fullscreen mode Exit fullscreen mode

stduuid [link]

I use UUIDs on the timers, so I needed a way to generate them. I could do it myself--but we're trying to not reinvent the whole wheel only some it.

stb [link]

The stb headers are great, they're single file units that each do some specific thing--in this case I use the ones for reading and writing images to disk. Great libraries, never done me wrong, I recommend them.

glm [link]

You need matrices to deal with anything in code OpenGL, and I'm not going to write that library myself. glm is a mature library for dealing with all the matrices and vectors that you have to use, including building projection matrices, and they are also very easily upload-able into vertex buffers. Neat!

Wrap up

That's all the 3rd party stuff that Nyx is using for now. If I add more libraries in the future I'll add them here.

Top comments (0)