I have implemented all the numbered chapters and some of the extra from vkguide.dev in Zig.
I originally shared this post on reddit, but it was suggested on the comments to also post it here, so apologies to anyone that happens to see it in both platforms.
- Dear Imgui
- AMD VMA
- Vulkan (system, the other libraries are included in the repo)
Everything else is written from scratch:
- Obj loader
- Vulkan bootstrap code
- Shader compilation through build.zig
I wrote this as a learning experience and I have included some of my thoughts in the readme.
Not looking for stars or anything, I just thought I would share in case someone was trying to achieve something similar.
Of course, I still consider myself a newbie at zig, so all feedback of any kind is welcome (and yes, you can tell me I should not snake case function names, but I like it better that way :))
Repo here: vkguide-zig
Great, thanks for sharing!
BTW, I sometimes think of pushing code on public GitHub as kind of blogging - it’s fine if it’s not directly useful, novel or expert level.
Great job, thank you for sharing!
BTW, what is your approach to third party libraries, like
I mean, I’m hesitant about just dropping them in my own github repositories, because… well, they’re not mine and I wouldn’t want to upset their authors.
But telling somebody who just wishes to compile and run your project to go through the hassle of getting the dependencies manually, and risking that the version they’d be getting won’t play nice with your project… such a pain.
cimgui itself does contain a link to
imgui as a submodule, maybe this is the solution.
Thank you for the kind words.
Regarding third party libraries, the license for all the dependencies allows you to share the code as long as you are compliant with the terms.
VMA and stb libraries are header only and the license terms are embedded in the source file.
SDL also embeds it in every file.
ImGui did not and I didn’t copy it, which was my mistake, and I now fixed it (thank you for asking the question and make me double check).
In general I prefer to have the code in the repo or automatically fetched through other means that are version aware (say zig package manager or cargo etc.).
No submodules or anything like that.
Ideally most people should be able to clone the repo, give a build command and have it work.
Regarding imgui in particular, I have generated the bindings unsing dear_bindings for the library and 2 backends (this also generates a cimgui.h file, but it is not the same as cimgui. See: dear_bindings).
It would be unreasonable and daunting to ask to anyone to clone the repo, find the right branch of imgui (docking), at the right commit, generate all 3 bindings by hand etc.
And regarding the authors, as I mentioned the license they chose allows you to use their code and I always make sure to credit them in a few extra places (like the readme)
I have tried to use dear_bindings from Zig a few months ago, and something didn’t work for me, I can’t recall what it was.
The pre-built one from the release page didn’t work for me either. And if you need the backends those do not work either.
I ended up recreating all the bindings from scratch.
Those are the steps:
- Cloned imgui and switched to the branch/version I wanted;
- Copied in the project only the root .h and .cpp file and the 2 pairs of .h/.cpp for the backend I needed, all in the same directory;
- Downloaded the zip (or clone) dear_binding;
- From the binding directory, generate the 3 bindings I needed:
python dear_bindings.py -o cimgui path/to/imgui.h
python dear_bindings.py --backed -o cimgui_impl_sdl3 path/to/imgui_impl_sdl3.h
python dear_bindings.py --backed -o cimgui_impl_vulkan path/to/imgui_impl_vulkan.h
- Copy the 6 resulting file (9 if you want to keep the .json) from the binding directory to the thirdparty imgui directory in the project
To be able run it, you need python (I used 3.11, but at least 3.8+) and ply (which you can get from pip or your system package manager in some cases like arch pacman)
I’m currently using
cimgui for my “playground” Zig projects (+ OpenGL via GLAD + GLFW), but I now know who to turn to if I get stuck
I’ve tried starting with Vulkan a couple of years ago (in C), learned a few things, but never got to “your first triangle” stage. Gotta learn these things one step at a time, I’ll just stick to OpenGL for now.
TBH, for CAD-type applications (my current goal), Vulkan may be an overkill, at least nowadays (but then there’s Vulkan Compute…).
One of the reasons why I picked this project is that vkguide proved to be the best tutorial I have found on Vulkan.
But compute is not touched until the extra chapters and, in any case, vulkan remains a lot more complicated than OGL.
I am happy to help if I can with imgui, but my area of expertise and day job are as gamedev. My experience with cad begins and end with making stuff to 3d print in fusion