# zig-gamedev **Repository Path**: cekongnet/zig-gamedev ## Basic Information - **Project Name**: zig-gamedev - **Description**: zig game development repo, clone https://github.com/michal-z/zig-gamedev - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2022-02-01 - **Last Updated**: 2023-09-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README **Please note that the project requires latest Zig compiler (master/nightly). It can be downloaded [here](https://ziglang.org/download/).** [Libraries](#libraries) - [Sample applications](#sample-applications-native-wgpu) - [Vision](#vision) - [Others using zig-gamedev](#others-using-zig-gamedev) - [Monthly reports](https://github.com/michal-z/zig-gamedev/wiki/Progress-Reports) - [Roadmap](https://github.com/michal-z/zig-gamedev/wiki/Roadmap) # zig-gamedev project We build game development ecosystem for [Zig programming language](https://ziglang.org/), everyday since July 2021. Please consider [supporting the project](https://github.com/sponsors/michal-z). We create: * Cross-platform and composable [libraries](#libraries) * Cross-platform [sample applications](#sample-applications-native-wgpu) * DirectX 12 [sample applications](#sample-applications-directx-12) * Mini-games (in planning) To get started on Windows/Linux/macOS try out [physically based rendering (wgpu)](https://github.com/michal-z/zig-gamedev/tree/main/samples/physically_based_rendering_wgpu) sample: ``` git clone https://github.com/michal-z/zig-gamedev.git cd zig-gamedev zig build physically_based_rendering_wgpu-run ``` ## Quick start (D3D12) To use zig-gamedev in your project copy or download zig-gamedev as a sumboulde, for example: ```sh git submodule add https://github.com/michal-z/zig-gamedev.git libs/zig-gamedev ``` Currently we have minimal low-level API which allows you to build the lib once (`package()`) and link it with many executables (`link()`). Include neccessary libraries in `build.zig` like: ```zig // Fetch the library const zwin32 = @import("src/deps/zig-gamedev/libs/zwin32/build.zig"); // Build it const zwin32_pkg = zwin32.package(b, target, optimize, .{}); // Link with your app zwin32_pkg.link(exe, .{ .d3d12 = true }); ```
Example build script: ```zig const std = @import("std"); const zwin32 = @import("libs/zig-gamedev/libs/zwin32/build.zig"); const common = @import("libs/zig-gamedev/libs/common/build.zig"); const zd3d12 = @import("libs/zig-gamedev/libs/zd3d12/build.zig"); pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const exe = b.addExecutable(.{ .name = "example", .root_source_file = .{ .path = "src/main.zig" }, .target = target, .optimize = optimize, }); b.installArtifact(exe); const run_cmd = b.addRunArtifact(exe); run_cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| { run_cmd.addArgs(args); } const zwin32_pkg = zwin32.package(b, target, optimize, .{}); const zd3d12_pkg = zd3d12.package(b, target, optimize, .{ .options = .{ .enable_debug_layer = false, .enable_gbv = false, .enable_d2d = true, }, .deps = .{ .zwin32 = zwin32_pkg.zwin32 }, }); const common_d2d_pkg = common.package(b, target, optimize, .{ .deps = .{ .zwin32 = zwin32_pkg.zwin32, .zd3d12 = zd3d12_pkg.zd3d12 }, }); zwin32_pkg.link(exe, .{ .d3d12 = true }); zd3d12_pkg.link(exe); common_d2d_pkg.link(exe); const run_step = b.step("run", "Run the app"); run_step.dependOn(&run_cmd.step); } ```
## Libraries Library | Latest version | Description ------- | --------- | --------------- **[zphysics](libs/zphysics)** | 0.0.6 | Zig API and C API for [Jolt Physics](https://github.com/jrouwe/JoltPhysics) **[zflecs](libs/zflecs)** | 0.0.1 | Zig bindings for [flecs](https://github.com/SanderMertens/flecs) ECS **[zopengl](libs/zopengl)** | 0.1.0 | OpenGL loader (supports 3.3 Core Profile and ES 2.0 Profile) **[zsdl](libs/zsdl)** | 0.0.1 | Bindings for SDL2 (wip) **[zgpu](libs/zgpu)** | 0.9.0 | Small helper library built on top of native wgpu implementation ([Dawn](https://github.com/michal-z/dawn-bin)) **[zgui](libs/zgui)** | 1.89.6 | Easy to use [dear imgui](https://github.com/ocornut/imgui) bindings (includes [ImPlot](https://github.com/epezent/implot)) **[zaudio](libs/zaudio)** | 0.9.3 | Fully-featured audio library built on top of [miniaudio](https://github.com/mackron/miniaudio) **[zmath](libs/zmath)** | 0.9.6 | SIMD math library for game developers **[zstbi](libs/zstbi)** | 0.9.3 | Image reading, writing and resizing with [stb](https://github.com/nothings/stb) libraries **[zmesh](libs/zmesh)** | 0.9.0 | Loading, generating, processing and optimizing triangle meshes **[ztracy](libs/ztracy)** | 0.9.0 | Support for CPU profiling with [Tracy](https://github.com/wolfpld/tracy) **[zpool](libs/zpool)** | 0.9.0 | Generic pool & handle implementation **[zglfw](libs/zglfw)** | 0.5.2 | Minimalistic [GLFW](https://github.com/glfw/glfw) bindings with no translate-c dependency **[znoise](libs/znoise)** | 0.1.0 | Zig bindings for [FastNoiseLite](https://github.com/Auburn/FastNoiseLite) **[zjobs](libs/zjobs)** | 0.1.0 | Generic job queue implementation **[zbullet](libs/zbullet)** | 0.2.0 | Zig bindings and C API for [Bullet physics library](https://github.com/bulletphysics/bullet3) **[zwin32](libs/zwin32)** | 0.9.0 | Zig bindings for Win32 API (d3d12, d3d11, xaudio2, directml, wasapi and more) **[zd3d12](libs/zd3d12)** | 0.9.0 | Helper library for DirectX 12 **[zxaudio2](libs/zxaudio2)** | 0.9.0 | Helper library for XAudio2 **[zpix](libs/zpix)** | 0.9.0 | Support for GPU profiling with PIX for Windows ## Vision * Very modular "toolbox of libraries", user can use only the components she needs * Works on Windows, macOS and Linux * Has zero dependency except [Zig compiler (master)](https://ziglang.org/download/) and `git` with [Git LFS](https://git-lfs.github.com/) - no Visual Studio, Build Tools, Windows SDK, gcc, dev packages, system headers/libs, cmake, ninja, etc. is needed * Building is as easy as running `zig build` (see: [Building](#building-sample-applications)) * Libraries are written from scratch in Zig *or* provide Ziggified bindings for carefully selected C/C++ libraries * Uses native wgpu implementation ([Dawn](https://github.com/michal-z/dawn-bin)) or OpenGL for cross-platfrom graphics and DirectX 12 for low-level graphics on Windows ## Sample applications (native wgpu) Some of the sample applications are listed below. More can be found in [samples](samples/) directory. 1. [physically based rendering (wgpu)](samples/physically_based_rendering_wgpu): This sample implements physically-based rendering (PBR) and image-based lighting (IBL) to achive realistic looking rendering results.
`zig build physically_based_rendering_wgpu-run` physically based rendering (wgpu) 1. [audio experiments (wgpu)](samples/audio_experiments_wgpu): This sample lets the user to experiment with audio and observe data that feeds the hardware.
`zig build audio_experiments_wgpu-run` audio experiments (wgpu) 1. [bullet physics test (wgpu)](samples/bullet_physics_test_wgpu): This sample application demonstrates how to use full 3D physics engine in your Zig programs.
`zig build bullet_physics_test_wgpu-run` bullet physics test (wgpu) 1. [procedural mesh (wgpu)](samples/procedural_mesh_wgpu): This sample shows how to efficiently draw several procedurally generated meshes.
`zig build procedural_mesh_wgpu-run` procedural mesh (wgpu) 1. [gui test (wgpu)](samples/gui_test_wgpu): This sample shows how to use our [zgui](libs/zgui) library.
`zig build gui_test_wgpu-run` gui test (wgpu) ## Sample applications (DirectX 12) Some of the sample applications are listed below. More can be found in [samples](samples/) directory. They can be built and run on Windows and Linux (Wine + VKD3D-Proton 2.8+): 1. [bindless](samples/bindless): This sample implements physically based shading and image based lighting to achive realistic looking rendering results. It uses bindless textures and HLSL 6.6 dynamic resources.
`zig build bindless-run` bindless 1. [rasterization](samples/rasterization): This sample application shows how GPU rasterizes triangles in slow motion.
`zig build rasterization-run` rasterization 1. [simple raytracer](samples/simple_raytracer): This sample implements basic hybrid renderer. It uses rasterization to resolve primary rays and raytracing (DXR) for shadow rays.
`zig build simple_raytracer-run` simple raytracer 1. [mesh shader test](samples/mesh_shader_test): This sample shows how to use DirectX 12 Mesh Shader.
`zig build mesh_shader_test-run` mesh shader test ## Others using zig-gamedev * [Aftersun](https://github.com/foxnne/aftersun) - Top-down 2D RPG * [Pixi](https://github.com/foxnne/pixi) - Pixel art editor made with Zig * [Simulations](https://github.com/ckrowland/simulations) - GPU Accelerated agent-based modeling to visualize and simulate complex systems * [elvengroin legacy](https://github.com/Srekel/elvengroin-legacy) - TBD * [jok](https://github.com/jack-ji/jok) - A minimal 2D/3D game framework for Zig ## Building sample applications To build all sample applications (assuming `zig` is in the PATH and [Git LFS](https://git-lfs.github.com/) is installed): 1. `git clone https://github.com/michal-z/zig-gamedev.git` 1. `cd zig-gamedev` 1. `zig build` Build artifacts will show up in `zig-out/bin` folder. `zig build ` will build sample application named ``. `zig build -run` will build and run sample application named ``. To list all available sample names run `zig build --help` and navigate to `Steps` section. #### Build options Options for Windows applications: * `-Dzd3d12-enable-debug-layer=[bool]` - Direct3D 12, Direct2D, DXGI debug layers enabled * `-Dzd3d12-enable-gbv=[bool]` - Direct3D 12 GPU-Based Validation (GBV) enabled * `-Dzpix-enable=[bool]` - PIX markers and events enabled ## GitHub Sponsors Thanks to all people who sponsor zig-gamedev project! In particular, these fine folks sponsor zig-gamedev for $25/month or more: * **[Derek Collison (derekcollison)](https://github.com/derekcollison)** * [Garett Bass (garettbass)](https://github.com/garettbass) * [Connor Rowland (ckrowland)](https://github.com/ckrowland) * Zig Software Foundation (ziglang) * Joran Dirk Greef (jorangreef)