136 lines
2.9 KiB
Zig
136 lines
2.9 KiB
Zig
const std = @import("std");
|
|
|
|
const zglfw = @import("zglfw");
|
|
const zgui = @import("zgui");
|
|
|
|
const main = @import("main.zig");
|
|
|
|
var show_console: bool = false;
|
|
var show_demo_window: bool = false;
|
|
|
|
const Vertex = extern struct {
|
|
position: [3]f32,
|
|
tex_coord: [2]f32,
|
|
normal: [3]f32,
|
|
tangent: [4]f32,
|
|
|
|
pub fn init(x: f32, y: f32, z: f32, u: f32, v: f32, nx: f32, ny: f32, nz: f32, tx: f32, ty: f32, tz: f32, tw: f32) Vertex {
|
|
return .{
|
|
.position = .{ x, y, z },
|
|
.tex_coord = .{ u, v },
|
|
.normal = .{ nx, ny, nz },
|
|
.tangent = .{ tx, ty, tw, tz },
|
|
};
|
|
}
|
|
};
|
|
|
|
const vertex_buffer = [_]Vertex{
|
|
Vertex.init(-0.5, -0.5, 0, 0, 1, 0, 0, 1, 1, 0, 0, -1),
|
|
Vertex.init(0.5, -0.5, 0, 1, 1, 0, 0, 1, 1, 0, 0, -1),
|
|
Vertex.init(-0.5, 0.5, 0, 0, 0, 0, 0, 1, 1, 0, 0, -1),
|
|
Vertex.init(0.5, 0.5, 0, 1, 0, 0, 0, 1, 1, 0, 0, -1),
|
|
};
|
|
|
|
const index_buffer = [_]u16{ 0, 1, 2, 2, 1, 3 };
|
|
|
|
pub fn init() void {}
|
|
|
|
pub fn update(dt: f32) void {
|
|
_ = dt;
|
|
|
|
if (show_console) {
|
|
showConsole();
|
|
}
|
|
|
|
if (show_demo_window) {
|
|
zgui.showDemoWindow(&show_demo_window);
|
|
}
|
|
}
|
|
|
|
pub fn charCallback(
|
|
_: *zglfw.Window,
|
|
codepoint: u32,
|
|
) callconv(.C) void {
|
|
_ = codepoint;
|
|
}
|
|
|
|
pub fn cursorPosCallback(
|
|
_: *zglfw.Window,
|
|
xpos: f64,
|
|
ypos: f64,
|
|
) callconv(.C) void {
|
|
_ = xpos;
|
|
_ = ypos;
|
|
}
|
|
|
|
pub fn keyCallback(
|
|
_: *zglfw.Window,
|
|
key: zglfw.Key,
|
|
scancode: c_int,
|
|
action: zglfw.Action,
|
|
mods: zglfw.Mods,
|
|
) callconv(.C) void {
|
|
_ = scancode;
|
|
|
|
const no_mods = @as(c_int, @bitCast(mods)) == 0;
|
|
|
|
if (key == .grave_accent and action == .press and no_mods) {
|
|
show_console = !show_console;
|
|
}
|
|
|
|
if (key == .F1 and action == .press and no_mods) {
|
|
show_demo_window = true;
|
|
}
|
|
}
|
|
|
|
pub fn mouseButtonCallback(
|
|
_: *zglfw.Window,
|
|
button: zglfw.MouseButton,
|
|
action: zglfw.Action,
|
|
mods: zglfw.Mods,
|
|
) callconv(.C) void {
|
|
_ = button;
|
|
_ = action;
|
|
_ = mods;
|
|
}
|
|
|
|
pub fn scrollCallback(
|
|
_: *zglfw.Window,
|
|
xoffset: f64,
|
|
yoffset: f64,
|
|
) callconv(.C) void {
|
|
_ = xoffset;
|
|
_ = yoffset;
|
|
}
|
|
|
|
pub fn deinit() void {}
|
|
|
|
fn showConsole() void {
|
|
const display_size = zgui.io.getDisplaySize();
|
|
zgui.setNextWindowPos(.{
|
|
.x = 0,
|
|
.y = 0,
|
|
});
|
|
zgui.setNextWindowSize(.{
|
|
.w = display_size[0],
|
|
.h = main.min_window_height,
|
|
.cond = .once,
|
|
});
|
|
if (zgui.begin("Console", .{ .flags = .{
|
|
.no_title_bar = true,
|
|
.no_resize = true,
|
|
.no_move = true,
|
|
.no_collapse = true,
|
|
} })) {
|
|
for (main.logs.items) |log| {
|
|
zgui.textUnformattedColored(switch (log.level) {
|
|
.err => .{ 1, 0, 0, 1 },
|
|
.warn => .{ 1, 1, 0, 1 },
|
|
.info => .{ 1, 1, 1, 1 },
|
|
.debug => .{ 0.5, 0.5, 0.5, 1 },
|
|
}, log.message);
|
|
}
|
|
}
|
|
zgui.end();
|
|
}
|