create new project
This commit is contained in:
parent
d297576147
commit
5083326358
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/zig-cache/
|
||||
/zig-out/
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "thirdparty/zig-gamedev"]
|
||||
path = thirdparty/zig-gamedev
|
||||
url = https://github.com/zig-gamedev/zig-gamedev/
|
37
build.zig
Normal file
37
build.zig
Normal file
@ -0,0 +1,37 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const hypatia = b.addExecutable(.{
|
||||
.name = "hypatia",
|
||||
|
||||
.root_source_file = .{
|
||||
.path = "main.zig",
|
||||
},
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
const zglfw = b.dependency("zglfw", .{});
|
||||
hypatia.root_module.addImport("zglfw", zglfw.module("root"));
|
||||
hypatia.linkLibrary(zglfw.artifact("glfw"));
|
||||
|
||||
const zgpu = b.dependency("zgpu", .{});
|
||||
hypatia.root_module.addImport("zgpu", zgpu.module("root"));
|
||||
hypatia.linkLibrary(zgpu.artifact("zdawn"));
|
||||
|
||||
const zgui = b.dependency("zgui", .{
|
||||
.shared = false,
|
||||
.with_implot = false,
|
||||
.backend = .glfw_wgpu,
|
||||
});
|
||||
hypatia.root_module.addImport("zgui", zgui.module("root"));
|
||||
hypatia.linkLibrary(zgui.artifact("imgui"));
|
||||
|
||||
@import("system_sdk").addLibraryPathsTo(hypatia);
|
||||
@import("zgpu").addLibraryPathsTo(hypatia);
|
||||
|
||||
b.installArtifact(hypatia);
|
||||
}
|
38
build.zig.zon
Normal file
38
build.zig.zon
Normal file
@ -0,0 +1,38 @@
|
||||
.{
|
||||
.name = "hypatia",
|
||||
.version = "0.0.1",
|
||||
.paths = .{
|
||||
"build.zig",
|
||||
"build.zig.zon",
|
||||
"main.zig",
|
||||
"thirdparty",
|
||||
},
|
||||
|
||||
.dependencies = .{
|
||||
.system_sdk = .{ .path = "thirdparty/zig-gamedev/libs/system-sdk", },
|
||||
.zglfw = .{ .path = "thirdparty/zig-gamedev/libs/zglfw", },
|
||||
.zgpu = .{ .path = "thirdparty/zig-gamedev/libs/zgpu", },
|
||||
.zgui = .{ .path = "thirdparty/zig-gamedev/libs/zgui", },
|
||||
|
||||
.dawn_x86_64_windows_gnu = .{
|
||||
.url = "https://github.com/michal-z/webgpu_dawn-x86_64-windows-gnu/archive/d3a68014e6b6b53fd330a0ccba99e4dcfffddae5.tar.gz",
|
||||
.hash = "1220f9448cde02ef3cd51bde2e0850d4489daa0541571d748154e89c6eb46c76a267",
|
||||
},
|
||||
.dawn_x86_64_linux_gnu = .{
|
||||
.url = "https://github.com/michal-z/webgpu_dawn-x86_64-linux-gnu/archive/7d70db023bf254546024629cbec5ee6113e12a42.tar.gz",
|
||||
.hash = "12204a3519efd49ea2d7cf63b544492a3a771d37eda320f86380813376801e4cfa73",
|
||||
},
|
||||
.dawn_aarch64_linux_gnu = .{
|
||||
.url = "https://github.com/michal-z/webgpu_dawn-aarch64-linux-gnu/archive/c1f55e740a62f6942ff046e709ecd509a005dbeb.tar.gz",
|
||||
.hash = "12205cd13f6849f94ef7688ee88c6b74c7918a5dfb514f8a403fcc2929a0aa342627",
|
||||
},
|
||||
.dawn_aarch64_macos = .{
|
||||
.url = "https://github.com/michal-z/webgpu_dawn-aarch64-macos/archive/d2360cdfff0cf4a780cb77aa47c57aca03cc6dfe.tar.gz",
|
||||
.hash = "12201fe677e9c7cfb8984a36446b329d5af23d03dc1e4f79a853399529e523a007fa",
|
||||
},
|
||||
.dawn_x86_64_macos = .{
|
||||
.url = "https://github.com/michal-z/webgpu_dawn-x86_64-macos/archive/901716b10b31ce3e0d3fe479326b41e91d59c661.tar.gz",
|
||||
.hash = "1220b1f02f2f7edd98a078c64e3100907d90311d94880a3cc5927e1ac009d002667a",
|
||||
},
|
||||
},
|
||||
}
|
99
main.zig
Normal file
99
main.zig
Normal file
@ -0,0 +1,99 @@
|
||||
const std = @import("std");
|
||||
|
||||
const zglfw = @import("zglfw");
|
||||
const zgpu = @import("zgpu");
|
||||
const wgpu = zgpu.wgpu;
|
||||
const zgui = @import("zgui");
|
||||
|
||||
pub fn main() !void {
|
||||
try zglfw.init();
|
||||
defer zglfw.terminate();
|
||||
|
||||
zglfw.windowHintTyped(.client_api, .no_api);
|
||||
|
||||
const window = try zglfw.Window.create(800, 500, "HELLOWORLD", null);
|
||||
defer window.destroy();
|
||||
window.setSizeLimits(400, 400, -1, -1);
|
||||
|
||||
var gpa_state = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
defer _ = gpa_state.deinit();
|
||||
const gpa = gpa_state.allocator();
|
||||
|
||||
const gctx = try zgpu.GraphicsContext.create(
|
||||
gpa,
|
||||
.{
|
||||
.window = window,
|
||||
.fn_getTime = @ptrCast(&zglfw.getTime),
|
||||
.fn_getFramebufferSize = @ptrCast(&zglfw.Window.getFramebufferSize),
|
||||
.fn_getWin32Window = @ptrCast(&zglfw.getWin32Window),
|
||||
.fn_getX11Display = @ptrCast(&zglfw.getX11Display),
|
||||
.fn_getX11Window = @ptrCast(&zglfw.getX11Window),
|
||||
.fn_getWaylandDisplay = @ptrCast(&zglfw.getWaylandDisplay),
|
||||
.fn_getWaylandSurface = @ptrCast(&zglfw.getWaylandWindow),
|
||||
.fn_getCocoaWindow = @ptrCast(&zglfw.getCocoaWindow),
|
||||
},
|
||||
.{},
|
||||
);
|
||||
defer gctx.destroy(gpa);
|
||||
|
||||
zgui.init(gpa);
|
||||
defer zgui.deinit();
|
||||
|
||||
zgui.backend.init(
|
||||
window,
|
||||
gctx.device,
|
||||
@intFromEnum(zgpu.GraphicsContext.swapchain_format),
|
||||
@intFromEnum(wgpu.TextureFormat.undef),
|
||||
);
|
||||
defer zgui.backend.deinit();
|
||||
|
||||
var prev_scale: f32 = 1.0;
|
||||
while (!window.shouldClose() and window.getKey(.escape) != .press) {
|
||||
zglfw.pollEvents();
|
||||
|
||||
const scale_factor = scale_factor: {
|
||||
const scale = window.getContentScale();
|
||||
break :scale_factor @max(scale[0], scale[1]);
|
||||
};
|
||||
std.debug.print("{}", .{scale_factor / prev_scale});
|
||||
zgui.getStyle().scaleAllSizes(scale_factor / prev_scale);
|
||||
prev_scale = scale_factor;
|
||||
|
||||
zgui.backend.newFrame(
|
||||
gctx.swapchain_descriptor.width,
|
||||
gctx.swapchain_descriptor.height,
|
||||
);
|
||||
|
||||
// Set the starting window position and size to custom values
|
||||
zgui.setNextWindowPos(.{ .x = 20.0, .y = 20.0, .cond = .first_use_ever });
|
||||
zgui.setNextWindowSize(.{ .w = -1.0, .h = -1.0, .cond = .first_use_ever });
|
||||
|
||||
if (zgui.begin("My window", .{})) {
|
||||
if (zgui.button("Press me!", .{ .w = 200.0 })) {
|
||||
std.debug.print("Button pressed\n", .{});
|
||||
}
|
||||
}
|
||||
zgui.end();
|
||||
|
||||
const swapchain_texv = gctx.swapchain.getCurrentTextureView();
|
||||
defer swapchain_texv.release();
|
||||
|
||||
const commands = commands: {
|
||||
const encoder = gctx.device.createCommandEncoder(null);
|
||||
defer encoder.release();
|
||||
|
||||
// GUI pass
|
||||
{
|
||||
const pass = zgpu.beginRenderPassSimple(encoder, .load, swapchain_texv, null, null, null);
|
||||
defer zgpu.endReleasePass(pass);
|
||||
zgui.backend.draw(pass);
|
||||
}
|
||||
|
||||
break :commands encoder.finish(null);
|
||||
};
|
||||
defer commands.release();
|
||||
|
||||
gctx.submit(&.{commands});
|
||||
_ = gctx.present();
|
||||
}
|
||||
}
|
1
thirdparty/zig-gamedev
vendored
Submodule
1
thirdparty/zig-gamedev
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 09cb2d2bd814f6856f437ef2c9cb051abb068a54
|
Loading…
Reference in New Issue
Block a user