Skip to content

Commit f2c18c8

Browse files
committed
Dear ImGui window
1 parent 532e8a1 commit f2c18c8

File tree

4 files changed

+164
-0
lines changed

4 files changed

+164
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ libs/**/zig-cache
88
!src/**/*.zig
99
virtual_environment
1010
!.gitignore
11+
!build.zig
12+
!build.zig.zon
1113
!main.py
1214
!README.md
1315
!requirements.txt

build.zig

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
const std = @import("std");
2+
3+
const zgui = @import("libs/zgui/build.zig");
4+
5+
// Needed for glfw/wgpu rendering backend
6+
const zglfw = @import("libs/zglfw/build.zig");
7+
const zgpu = @import("libs/zgpu/build.zig");
8+
const zpool = @import("libs/zpool/build.zig");
9+
10+
// Although this function looks imperative, note that its job is to
11+
// declaratively construct a build graph that will be executed by an external
12+
// runner.
13+
pub fn build(b: *std.Build) void {
14+
// Standard target options allows the person running `zig build` to choose
15+
// what target to build for. Here we do not override the defaults, which
16+
// means any target is allowed, and the default is native. Other options
17+
// for restricting supported target set are available.
18+
const target = b.standardTargetOptions(.{});
19+
20+
// Standard optimization options allow the person running `zig build` to select
21+
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
22+
// set a preferred release mode, allowing the user to decide how to optimize.
23+
const optimize = b.standardOptimizeOption(.{});
24+
25+
const exe = b.addExecutable(.{
26+
.name = "cc-legacy-mod-converter",
27+
// In this case the main source file is merely a path, however, in more
28+
// complicated build scripts, this could be a generated file.
29+
.root_source_file = .{ .path = "src/main.zig" },
30+
.target = target,
31+
.optimize = optimize,
32+
});
33+
34+
const zgui_pkg = zgui.package(b, target, optimize, .{
35+
.options = .{ .backend = .glfw_wgpu },
36+
});
37+
38+
zgui_pkg.link(exe);
39+
40+
// Needed for glfw/wgpu rendering backend
41+
const zglfw_pkg = zglfw.package(b, target, optimize, .{});
42+
const zpool_pkg = zpool.package(b, target, optimize, .{});
43+
const zgpu_pkg = zgpu.package(b, target, optimize, .{
44+
.deps = .{ .zpool = zpool_pkg.zpool, .zglfw = zglfw_pkg.zglfw },
45+
});
46+
47+
zglfw_pkg.link(exe);
48+
zgpu_pkg.link(exe);
49+
50+
// This declares intent for the executable to be installed into the
51+
// standard location when the user invokes the "install" step (the default
52+
// step when running `zig build`).
53+
b.installArtifact(exe);
54+
55+
// This *creates* a Run step in the build graph, to be executed when another
56+
// step is evaluated that depends on it. The next line below will establish
57+
// such a dependency.
58+
const run_cmd = b.addRunArtifact(exe);
59+
60+
// By making the run step depend on the install step, it will be run from the
61+
// installation directory rather than directly from within the cache directory.
62+
// This is not necessary, however, if the application depends on other installed
63+
// files, this ensures they will be present and in the expected location.
64+
run_cmd.step.dependOn(b.getInstallStep());
65+
66+
// This allows the user to pass arguments to the application in the build
67+
// command itself, like this: `zig build run -- arg1 arg2 etc`
68+
if (b.args) |args| {
69+
run_cmd.addArgs(args);
70+
}
71+
72+
// This creates a build step. It will be visible in the `zig build --help` menu,
73+
// and can be selected like this: `zig build run`
74+
// This will evaluate the `run` step rather than the default, which is "install".
75+
const run_step = b.step("run", "Run the app");
76+
run_step.dependOn(&run_cmd.step);
77+
78+
// Creates a step for unit testing. This only builds the test executable
79+
// but does not run it.
80+
const unit_tests = b.addTest(.{
81+
.root_source_file = .{ .path = "src/main.zig" },
82+
.target = target,
83+
.optimize = optimize,
84+
});
85+
86+
const run_unit_tests = b.addRunArtifact(unit_tests);
87+
88+
// Similar to creating the run step earlier, this exposes a `test` step to
89+
// the `zig build --help` menu, providing a way for the user to request
90+
// running the unit tests.
91+
const test_step = b.step("test", "Run unit tests");
92+
test_step.dependOn(&run_unit_tests.step);
93+
}

build.zig.zon

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.{
2+
.name = "zig-gamedev",
3+
.version = "0.1.0",
4+
.dependencies = .{
5+
.dawn_x86_64_windows_gnu = .{
6+
.url = "https://github.com/michal-z/webgpu_dawn-x86_64-windows-gnu/archive/d3a68014e6b6b53fd330a0ccba99e4dcfffddae5.tar.gz",
7+
.hash = "1220f9448cde02ef3cd51bde2e0850d4489daa0541571d748154e89c6eb46c76a267",
8+
},
9+
.dawn_x86_64_linux_gnu = .{
10+
.url = "https://github.com/michal-z/webgpu_dawn-x86_64-linux-gnu/archive/7d70db023bf254546024629cbec5ee6113e12a42.tar.gz",
11+
.hash = "12204a3519efd49ea2d7cf63b544492a3a771d37eda320f86380813376801e4cfa73",
12+
},
13+
.dawn_aarch64_linux_gnu = .{
14+
.url = "https://github.com/michal-z/webgpu_dawn-aarch64-linux-gnu/archive/c1f55e740a62f6942ff046e709ecd509a005dbeb.tar.gz",
15+
.hash = "12205cd13f6849f94ef7688ee88c6b74c7918a5dfb514f8a403fcc2929a0aa342627",
16+
},
17+
.dawn_aarch64_macos = .{
18+
.url = "https://github.com/michal-z/webgpu_dawn-aarch64-macos/archive/d2360cdfff0cf4a780cb77aa47c57aca03cc6dfe.tar.gz",
19+
.hash = "12201fe677e9c7cfb8984a36446b329d5af23d03dc1e4f79a853399529e523a007fa"
20+
},
21+
.dawn_x86_64_macos = .{
22+
.url = "https://github.com/michal-z/webgpu_dawn-x86_64-macos/archive/901716b10b31ce3e0d3fe479326b41e91d59c661.tar.gz",
23+
.hash = "1220b1f02f2f7edd98a078c64e3100907d90311d94880a3cc5927e1ac009d002667a",
24+
},
25+
}
26+
}

src/main.zig

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const std = @import("std");
2+
3+
const zglfw = @import("zglfw");
4+
const zgpu = @import("zgpu");
5+
const zgui = @import("zgui");
6+
7+
pub fn main() !void {
8+
zglfw.init() catch {
9+
std.log.err("Failed to initialize GLFW library.", .{});
10+
return;
11+
};
12+
defer zglfw.terminate();
13+
14+
const window = zglfw.Window.create(1600, 1000, "Legacy Mod Converter 1.0 for Pre-Release 5.2", null) catch {
15+
std.log.err("Failed to create window.", .{});
16+
return;
17+
};
18+
defer window.destroy();
19+
window.setSizeLimits(400, 400, -1, -1);
20+
21+
var gpa_state = std.heap.GeneralPurposeAllocator(.{}){};
22+
defer _ = gpa_state.deinit();
23+
const gpa = gpa_state.allocator();
24+
25+
const gctx = try zgpu.GraphicsContext.create(gpa, window, .{});
26+
defer gctx.destroy(gpa);
27+
28+
zgui.init(gpa);
29+
defer zgui.deinit();
30+
31+
_ = zgui.io.addFontFromFile("content/Roboto-Medium.ttf", 16.0);
32+
33+
zgui.backend.init(
34+
window,
35+
gctx.device,
36+
@intFromEnum(zgpu.GraphicsContext.swapchain_format),
37+
);
38+
defer zgui.backend.deinit();
39+
40+
while (!window.shouldClose()) {
41+
zglfw.pollEvents();
42+
}
43+
}

0 commit comments

Comments
 (0)