When zig meets bgfx.
  • C 63%
  • C++ 32.8%
  • Zig 2.6%
  • Shell 1%
  • Objective-C 0.4%
Find a file
Ondra Voves 91b0dd7159 Migrate to codeberg. (#1)
Reviewed-on: #1
Co-authored-by: Ondra Voves <[email protected]>
Co-committed-by: Ondra Voves <[email protected]>
2026-02-03 18:42:24 +01:00
.github/workflows Fix version and linux ci (#21) 2025-12-01 16:02:22 +01:00
examples Upgrade bgfx and bx + cleanup. (#20) 2025-11-30 15:01:25 +01:00
includes Initial commit. 2024-04-11 15:17:59 +02:00
libs Update bx and bgfx. (#22) 2025-12-22 19:36:35 +01:00
shaders Upgrade bgfx and bx + cleanup. (#20) 2025-11-30 15:01:25 +01:00
src Upgrade bgfx and bx + cleanup. (#20) 2025-11-30 15:01:25 +01:00
tools Upgrade to zig 0.15.1 and fix imgui backend. (#17) 2025-10-05 13:57:42 +02:00
.gitattributes Remove LFS content (#15) 2025-04-02 16:27:13 +02:00
.gitignore Upgrade zig to 0.13.0-dev.351+64ef45eb0 2024-06-04 14:28:07 +02:00
.gitmodules Update zig-gamedev libs. (#6) 2024-11-27 16:58:59 +01:00
AUTHORS.md Upgrade BGFX (#3) 2024-08-23 20:55:14 +02:00
build.zig Upgrade bgfx and bx + cleanup. (#20) 2025-11-30 15:01:25 +01:00
build.zig.zon Update bx and bgfx. (#22) 2025-12-22 19:36:35 +01:00
LICENSE Initial commit. 2024-04-11 15:17:59 +02:00
README.md Migrate to codeberg. (#1) 2026-02-03 18:42:24 +01:00

ZBgfx

GitHub Actions

When zig meets bgfx.

Features

  • Zig api.
  • Compile as standard zig library.
  • shaderc as build artifact.
  • Shader compile in build.zig to *.bin.h.
  • Shader compile in build.zig and embed as zig module. (this is zig equivalent of *.bin.h)
  • Shader compile from runtime via shaderc as child process.
  • Binding for DebugDraw API
  • imgui render backend. Use build option imgui_include to enable. ex. for zgui: .imgui_include = zgui.path("libs").getPath(b),
  • Zig based allocator.

Important

  • This is only zig binding. For BGFX stuff goto bgfx.
  • Github repository is only mirror. Development continues here

Warning

  • shaderc need some time to compile.

Note

  • If you build shaders/app and see something like run shaderc (shader.bin.h) stderr. This is not "true" error (build success), but only in debug build shader print some stuff to stderr and zig build catch it.

License

Folders libs, shaders is copy&paste from bgfx for more sell-contained experience and is licensed by LICENSEE

Zig binding is licensed by WTFPL

Zig version

Minimal is 0.15.1. But you know try your version and believe.

Bgfx version

Getting started

Copy zbgfx to a subdirectory of your project and then add the following to your build.zig.zon .dependencies:

    .zbgfx = .{ .path = "path/to/zbgfx" },

or use zig fetch --save ... way.

Then in your build.zig add:

pub fn build(b: *std.Build) void {
    const exe = b.addExecutable(.{ ... });

    const zbgfx = b.dependency("zbgfx", .{});
    exe.root_module.addImport("zbgfx", zbgfx.module("zbgfx"));
    exe.linkLibrary(zbgfx.artifact("bgfx"));

    // This install shaderc to install dir
    // For shader build in build =D check examples
    // b.installArtifact(zbgfx.artifact("shaderc"));
}

Usage

See examples for binding usage and bgfx for bgfx stuff.

Build options

Build option Default Description
imgui_include null Path to ImGui includes (need for imgui bgfx backend)
multithread true Compile with BGFX_CONFIG_MULTITHREADED
with_shaderc true Compile with shaderc

Examples

Run this for build all examples:

cd examples
zig build

00-Minimal

Minimal setup with GLFW for window and input.

examples/zig-out/bin/00-minimal
Key Description
v Vsync on/off
d Debug on/off

01-ZGui

Minimal setup for zgui/ImGui.

examples/zig-out/bin/01-zgui
Key Description
v Vsync on/off
d Debug on/off

02-Runtime shaderc

Basic usage of shader compile in runtime. Try edit shaders in zig-out/bin/shaders and hit r to recompile.

examples/zig-out/bin/02-runtime-shaderc
Key Description
v Vsync on/off
d Debug on/off
r Recompile shaders form file

03-debugdraw

DebugDraw api usage example.

examples/zig-out/bin/03-debugdraw
Key Description
v Vsync on/off
d Debug on/off