2022-05-17 17:08:53 +02:00
|
|
|
const std = @import("std");
|
2022-10-29 21:49:44 +02:00
|
|
|
const c = @import("ffi.zig").c;
|
2022-05-17 17:08:53 +02:00
|
|
|
const gui = @import("gui.zig");
|
2022-10-29 21:49:44 +02:00
|
|
|
const State = @import("State.zig");
|
2022-11-02 22:35:51 +01:00
|
|
|
const log = std.log.scoped(.main);
|
2022-05-17 17:08:53 +02:00
|
|
|
|
2024-02-11 13:10:53 +01:00
|
|
|
pub const std_options = std.Options{
|
|
|
|
.log_level = .debug,
|
2023-04-07 15:38:12 +02:00
|
|
|
};
|
2022-11-02 23:04:14 +01:00
|
|
|
|
2022-10-29 21:49:44 +02:00
|
|
|
pub fn main() !void {
|
2022-11-02 22:35:51 +01:00
|
|
|
log.info("initializing GLFW", .{});
|
2022-10-29 21:49:44 +02:00
|
|
|
_ = c.glfwSetErrorCallback(&glfwErrorCb);
|
|
|
|
if (c.glfwInit() == 0) {
|
|
|
|
return error.GlfwInit;
|
|
|
|
}
|
2022-05-17 17:08:53 +02:00
|
|
|
|
2022-10-29 21:49:44 +02:00
|
|
|
c.glfwWindowHint(c.GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
|
|
c.glfwWindowHint(c.GLFW_CONTEXT_VERSION_MINOR, 3);
|
|
|
|
c.glfwWindowHint(c.GLFW_TRANSPARENT_FRAMEBUFFER, c.GLFW_TRUE);
|
2022-05-17 17:08:53 +02:00
|
|
|
|
2022-11-02 22:35:51 +01:00
|
|
|
log.info("creating window", .{});
|
2022-10-29 21:49:44 +02:00
|
|
|
const win = c.glfwCreateWindow(500, 500, "playtwitch", null, null);
|
|
|
|
defer c.glfwTerminate();
|
2022-05-17 17:08:53 +02:00
|
|
|
|
2022-10-29 21:49:44 +02:00
|
|
|
c.glfwMakeContextCurrent(win);
|
|
|
|
c.glfwSwapInterval(1);
|
2022-05-17 17:08:53 +02:00
|
|
|
|
2022-11-02 22:35:51 +01:00
|
|
|
log.info("initializing GLEW", .{});
|
2022-10-29 21:49:44 +02:00
|
|
|
const glew_err = c.glewInit();
|
|
|
|
if (glew_err != c.GLEW_OK) {
|
|
|
|
std.log.err("GLEW init error: {s}", .{c.glewGetErrorString(glew_err)});
|
|
|
|
return error.GlewInit;
|
|
|
|
}
|
2022-05-17 17:08:53 +02:00
|
|
|
|
2022-11-02 22:35:51 +01:00
|
|
|
log.info("initializing ImGui", .{});
|
2022-10-29 21:49:44 +02:00
|
|
|
const ctx = c.igCreateContext(null);
|
|
|
|
defer c.igDestroyContext(ctx);
|
2022-05-17 17:08:53 +02:00
|
|
|
|
2022-10-29 21:49:44 +02:00
|
|
|
const io = c.igGetIO();
|
|
|
|
io.*.ConfigFlags |= c.ImGuiConfigFlags_NavEnableKeyboard;
|
|
|
|
io.*.IniFilename = null;
|
|
|
|
io.*.LogFilename = null;
|
|
|
|
|
|
|
|
_ = c.ImGui_ImplGlfw_InitForOpenGL(win, true);
|
|
|
|
defer c.ImGui_ImplGlfw_Shutdown();
|
|
|
|
|
|
|
|
_ = c.ImGui_ImplOpenGL3_Init("#version 330 core");
|
|
|
|
defer c.ImGui_ImplOpenGL3_Shutdown();
|
|
|
|
|
|
|
|
c.igStyleColorsDark(null);
|
|
|
|
@import("theme.zig").loadTheme(&c.igGetStyle().*.Colors);
|
2022-11-23 22:43:45 +01:00
|
|
|
const font = try @import("theme.zig").loadFont();
|
2022-10-29 21:49:44 +02:00
|
|
|
|
|
|
|
const state = try State.init(win.?);
|
|
|
|
defer state.deinit();
|
|
|
|
|
|
|
|
while (c.glfwWindowShouldClose(win) == 0) {
|
2022-10-29 23:41:15 +02:00
|
|
|
if (c.glfwGetWindowAttrib(win, c.GLFW_VISIBLE) == 0)
|
|
|
|
continue;
|
|
|
|
|
2022-10-29 21:49:44 +02:00
|
|
|
c.glfwPollEvents();
|
|
|
|
|
|
|
|
var win_width: c_int = 0;
|
|
|
|
var win_height: c_int = 0;
|
|
|
|
c.glfwGetWindowSize(win, &win_width, &win_height);
|
|
|
|
|
|
|
|
c.ImGui_ImplOpenGL3_NewFrame();
|
|
|
|
c.ImGui_ImplGlfw_NewFrame();
|
|
|
|
c.igNewFrame();
|
2022-11-23 22:43:45 +01:00
|
|
|
if (font) |f|
|
|
|
|
c.igPushFont(f);
|
2022-10-29 21:49:44 +02:00
|
|
|
|
|
|
|
const win_visible = c.igBegin(
|
2022-11-02 22:35:51 +01:00
|
|
|
"##main_win",
|
2022-10-29 21:49:44 +02:00
|
|
|
null,
|
|
|
|
c.ImGuiWindowFlags_NoMove |
|
|
|
|
c.ImGuiWindowFlags_NoResize |
|
|
|
|
c.ImGuiWindowFlags_NoDecoration |
|
|
|
|
c.ImGuiWindowFlags_NoBringToFrontOnFocus |
|
|
|
|
c.ImGuiWindowFlags_NoNavFocus,
|
|
|
|
);
|
|
|
|
|
|
|
|
c.igSetWindowPos_Vec2(
|
|
|
|
.{ .x = 0.0, .y = 0.0 },
|
|
|
|
c.ImGuiCond_Always,
|
|
|
|
);
|
|
|
|
c.igSetWindowSize_Vec2(
|
2023-06-27 23:00:13 +02:00
|
|
|
.{ .x = @floatFromInt(win_width), .y = @floatFromInt(win_height) },
|
2022-10-29 21:49:44 +02:00
|
|
|
c.ImGuiCond_Always,
|
|
|
|
);
|
|
|
|
|
2022-10-29 23:41:15 +02:00
|
|
|
if (win_visible) {
|
2022-10-29 21:49:44 +02:00
|
|
|
try gui.winContent(state);
|
|
|
|
}
|
|
|
|
|
2022-11-23 22:43:45 +01:00
|
|
|
if (font != null)
|
|
|
|
c.igPopFont();
|
|
|
|
|
2022-10-29 21:49:44 +02:00
|
|
|
c.igEnd();
|
|
|
|
|
|
|
|
c.igEndFrame();
|
|
|
|
|
|
|
|
c.glViewport(0, 0, win_width, win_height);
|
|
|
|
c.glClear(c.GL_COLOR_BUFFER_BIT);
|
|
|
|
c.glClearColor(0.0, 0.0, 0.0, 0.0);
|
|
|
|
|
|
|
|
c.igRender();
|
|
|
|
c.ImGui_ImplOpenGL3_RenderDrawData(c.igGetDrawData());
|
|
|
|
c.glfwSwapBuffers(win);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn glfwErrorCb(e: c_int, d: [*c]const u8) callconv(.C) void {
|
2022-11-02 22:35:51 +01:00
|
|
|
log.err("GLFW error {d}: {s}", .{ e, d });
|
2022-08-07 00:13:00 +02:00
|
|
|
}
|