GUI image implementation, player hotbar

This commit is contained in:
2026-09-20 22:31:46 +02:00
parent ff72311979
commit c3fa7115c8
6 changed files with 423 additions and 136 deletions

View File

@@ -713,6 +713,28 @@ pub fn init() !Game {
},
},
},
.{
.dst_set = gui.image_descriptor_set,
.dst_binding = 0,
.dst_array_element = 0,
.descriptor_type = .uniform_buffer,
.descriptor_infos = .{
.buffer = &.{
.{
.buffer = global_uniforms.buffer,
.offset = 0,
.range = vk.WHOLE_SIZE,
},
},
},
},
.{
.dst_set = gui.image_descriptor_set,
.dst_binding = 3,
.dst_array_element = 0,
.descriptor_type = .sampled_image,
.descriptor_infos = .{ .image = descriptor_images },
},
},
});
@@ -782,74 +804,7 @@ pub fn deinit(self: *Game) void {
}
pub fn update(self: *Game, dt: f32) void {
const swapchain = ctx.swapchain;
const gui = ctx.gui;
self.player.update(dt, &self.chunks);
const extent = swapchain.extent;
const framebuffer_size = vm.Vector2.init(
@floatFromInt(extent.width),
@floatFromInt(extent.height),
);
const crosshair_half_extent_px = 8;
const crosshair_half_width_px = 1;
gui.pushBox(.{
.background_color = .init(1, 1, 1, 0.5),
.border_color = .init(0, 0, 0, 1),
.position_sspx = framebuffer_size.mulScalar(0.5).add(.init(-crosshair_half_extent_px, -crosshair_half_width_px)),
.size_px = .init(2.0 * crosshair_half_extent_px, 2.0 * crosshair_half_width_px),
.border_width_px = 0,
.border_radius_px = 0,
});
gui.pushBox(.{
.background_color = .init(1, 1, 1, 0.5),
.border_color = .init(0, 0, 0, 1),
.position_sspx = framebuffer_size.mulScalar(0.5).add(.init(-crosshair_half_width_px, -crosshair_half_extent_px)),
.size_px = .init(2.0 * crosshair_half_width_px, 2.0 * crosshair_half_extent_px),
.border_width_px = 0,
.border_radius_px = 0,
});
{
const margin: f16 = 8;
const font_size: f32 = 16;
const player_position_sv = self.player.position_sv;
gui.pushBox(.{
.background_color = .init(0, 0, 0, 0.75),
.border_color = .init(0, 0, 0, 1),
.position_sspx = .init(0, 0),
.size_px = .init(157, 4 * margin + 3 * font_size),
.border_width_px = 0,
.border_radius_px = 0,
});
gui.printLine("X {X:0>8}", .{@as(u32, @bitCast(player_position_sv.x))}, .{
.position_sspx = .init(margin, margin + font_size),
.font_id = self.font,
.cap_height_px = font_size,
.color = .init(1, 1, 1, 1),
});
gui.printLine("Y {X:0>8}", .{@as(u32, @bitCast(player_position_sv.y))}, .{
.position_sspx = .init(margin, 2 * (margin + font_size)),
.font_id = self.font,
.cap_height_px = font_size,
.color = .init(1, 1, 1, 1),
});
gui.printLine("Z {X:0>8}", .{@as(u32, @bitCast(player_position_sv.z))}, .{
.position_sspx = .init(margin, 3 * (margin + font_size)),
.font_id = self.font,
.cap_height_px = font_size,
.color = .init(1, 1, 1, 1),
});
}
self.player.update(dt, self);
self.render() catch |err| {
std.log.err("Failed to render: {s}", .{@errorName(err)});