Hello folks! Following my last post Good project ideas for beginners, I’ve received recommendations for game development as a good playground for my Zig learning journey. And that seems like a pretty fun way of exploring Zig!
…The problem is that I don’t know about how the Zig ecosystem for game development is going. So, what I want is to make a simple 3d game using OpenGL, I don’t have any specific ideas in mind for now (but I certainly will when I start), I’d love recommendations about libraries and ways to be able to develop my game using Zig.
I don’t have any plans to publish anything, I’m just doing that for fun and learning, but it would be nice to have an environment where I can develop without limitations, regardless of whether my game is big or small
I like to use zgl as it has a nice ziggified wrapper around OpenGL. I had to generate a binding for 4.6 though.
zigglgen looks really cool and I would like to use it, but the zgl
wrapper is just too nice
For windowing I prefer mach-glfw which also has a nice zig wrapper API. To get it building on zig master I had to disable the comptime version check though.
In the past I used zlm for linear maths, but there’s a few options out there and I’m keen to try out some others!
3 Likes
It’s also worth noting that Zig has great C interop. You don’t necessarily need to use any bindings, instead you can just interface with the C libraries directly.
While bindings are nice I prefer directly using the C libraries, because that’s what all the OpenGL references use as well.
In your build file you can use exe.addCSourceFile
to add the implementation of header-only C libraries like glad.h
to the build, you can use exe.linkSystemLibrary
to link libraries like opengl and glfw and you can use exe.addIncludePath
to add the path to your library headers. These can be accessed in the code using @cImport
and @cInclude
. All of that works almost like you are used to in C/C++.
5 Likes
Outside of the libraries that have been mentioned above (I would also strongly recommend starting out with mach-glfw for windowing), you might want to take a look at zig-gamedev which offers a good collection of bindings and libraries that you can pick and choose from depending on your needs. In particular, zmath offers a nice set of optimized math routines, and in the past zsdl has served as an easy way of using SDL2 (by linking with prebuilt shared libraries copied from Steam) for windowing if you prefer SDL over GLFW.
Regarding OpenGL, there are dozens of bindings and wrappers out there and which one to recommend depends on whether you want a Ziggified wrapper that makes use of Zig language features, or a more pure C-like experience. zigglgen, the binding generator I wrote, belongs to the latter category and generates code that is functionally identical to @cImport
ing GLAD, except it attempts to annotate the optionality and arity of pointers to a greater accuracy than can be expressed in C.
4 Likes
Lots of options! I hope I can choose the best for me, mach-glfw seems to be the one for windows, as for OpenGL bindings for Zig… I wonder what drawbacks would come along with the alternative of @IntegratedQuantum
Time to start experimenting! Thanks everyone!!
1 Like