aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig
new file mode 100644
index 0000000..ce31e75
--- /dev/null
+++ b/src/main.zig
@@ -0,0 +1,83 @@
+const std = @import("std");
+const panic = std.debug.panic;
+const c = @import("c.zig");
+const debug_gl = @import("debug_gl.zig");
+const cfg = @import("config.zig");
+const out = @import("output.zig");
+
+var window: *c.GLFWwindow = undefined;
+
+fn errorCallback(err: c_int, description: [*c]const u8) callconv(.C) void {
+ panic("Error: {}\n", .{description});
+}
+
+pub fn main() !void {
+ var config = try cfg.Config.parse("config.yaml");
+ defer config.arena.deinit();
+
+ _ = c.glfwSetErrorCallback(errorCallback);
+
+ if (c.glfwInit() == c.GL_FALSE) {
+ panic("GLFW init failure\n", .{});
+ }
+ defer c.glfwTerminate();
+
+ c.glfwWindowHint(c.GLFW_CONTEXT_VERSION_MAJOR, 3);
+ c.glfwWindowHint(c.GLFW_CONTEXT_VERSION_MINOR, 2);
+ c.glfwWindowHint(c.GLFW_OPENGL_FORWARD_COMPAT, c.GL_TRUE);
+ c.glfwWindowHint(c.GLFW_OPENGL_DEBUG_CONTEXT, debug_gl.is_on);
+ c.glfwWindowHint(c.GLFW_OPENGL_PROFILE, c.GLFW_OPENGL_CORE_PROFILE);
+ c.glfwWindowHint(c.GLFW_DEPTH_BITS, 0);
+ c.glfwWindowHint(c.GLFW_STENCIL_BITS, 8);
+ c.glfwWindowHint(c.GLFW_VISIBLE, c.GLFW_FALSE);
+
+ window = c.glfwCreateWindow(config.width, config.height, "glsl-view", null, null) orelse {
+ panic("unable to create window\n", .{});
+ };
+ defer c.glfwDestroyWindow(window);
+
+ c.glfwMakeContextCurrent(window);
+ c.glfwSwapInterval(1);
+
+ c.glClearColor(0.0, 0.0, 0.0, 1.0);
+
+ // c.glEnable(c.GL_BLEND);
+ // c.glBlendFunc(c.GL_SRC_ALPHA, c.GL_ONE_MINUS_SRC_ALPHA);
+ // c.glPixelStorei(c.GL_UNPACK_ALIGNMENT, 1);
+
+ c.glViewport(0, 0, config.width, config.height);
+
+ debug_gl.assertNoError();
+
+ var outputs = try config.arena.allocator.alloc(*out.Output, config.outputs.len);
+ for (config.outputs) |output_config, i| {
+ outputs[i] = out.Output.create(&config.arena.allocator, output_config, window);
+ }
+ defer for (outputs) |output| {
+ output.destroy(output);
+ };
+
+ const start_time = c.glfwGetTime();
+ var prev_time = start_time;
+
+ while (c.glfwWindowShouldClose(window) == c.GL_FALSE) {
+ c.glClear(c.GL_COLOR_BUFFER_BIT | c.GL_DEPTH_BUFFER_BIT | c.GL_STENCIL_BUFFER_BIT);
+
+ const now_time = c.glfwGetTime();
+ const elapsed = now_time - prev_time;
+ prev_time = now_time;
+
+ for (outputs) |output| {
+ const close = output.update(output);
+ if (close) {
+ c.glfwSetWindowShouldClose(window, c.GL_TRUE);
+ }
+ }
+
+ c.glfwSwapBuffers(window);
+
+ c.glfwPollEvents();
+ }
+
+ debug_gl.assertNoError();
+}