aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/main.zig b/src/main.zig
index 6c2b0c4..41ad341 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -6,11 +6,12 @@ const debug_gl = @import("debug_gl.zig");
const cfg = @import("config.zig");
const out = @import("output.zig");
const gl = @import("gl.zig");
+const ctrl = @import("control.zig");
const c_allocator = @import("std").heap.c_allocator;
var window: *c.GLFWwindow = undefined;
-extern fn errorCallback(err: c_int, description: [*c]const u8) callconv(.C) void {
+fn errorCallback(err: c_int, description: [*c]const u8) callconv(.C) void {
panic("Error: {}\n", .{description});
}
@@ -28,7 +29,7 @@ pub fn main() !void {
var monitor_count: c_int = 0;
const monitors = c.glfwGetMonitors(&monitor_count);
for (monitors[0..@intCast(usize, monitor_count)]) |monitor, i| {
- std.debug.warn("monitor {}: '{s}'\n", .{ i, @ptrCast([*:0]const u8, c.glfwGetMonitorName(monitor))});
+ std.debug.warn("monitor {}: '{s}'\n", .{ i, @ptrCast([*:0]const u8, c.glfwGetMonitorName(monitor)) });
}
c.glfwWindowHint(c.GLFW_CONTEXT_VERSION_MAJOR, 4);
@@ -44,13 +45,13 @@ pub fn main() !void {
panic("unable to create window\n", .{});
};
defer c.glfwDestroyWindow(window);
-
+
c.glfwMakeContextCurrent(window);
c.glfwSwapInterval(1);
var constants = try gl.Constants.create(window);
defer constants.destroy();
-
+
var outputs = try std.ArrayList(*out.Output).initCapacity(&config.arena.allocator, config.outputs.len);
defer outputs.deinit();
for (config.outputs) |output_config, i| {
@@ -104,7 +105,10 @@ pub fn main() !void {
defer fbo.destroy();
var offset: f32 = 0;
-
+
+ const control = try ctrl.ControlServer.init(&config.arena.allocator);
+ defer control.destroy();
+
while (c.glfwWindowShouldClose(window) == c.GL_FALSE) {
c.glfwMakeContextCurrent(window);
c.glClear(c.GL_COLOR_BUFFER_BIT);
@@ -119,15 +123,19 @@ pub fn main() !void {
last_stat = stat;
}
+ control.update(main_program);
+
fbo.bind();
c.glClear(c.GL_COLOR_BUFFER_BIT);
-
+
main_program.bind();
offset += @floatCast(f32, elapsed / 4);
- main_program.setUniformFloat(main_program.uniformLocation("offset"), offset);
+ if (main_program.uniformLocation("offset")) |location| {
+ main_program.setUniform1f(location, offset);
+ } else |_| {}
constants.normalizedQuad.draw();
fbo.unbind();
-
+
for (outputs.toSlice()) |output, i| {
const close = output.update(output, fbo.texture_id);
if (close) {
@@ -139,7 +147,7 @@ pub fn main() !void {
if (outputs.len == 0)
break;
-
+
c.glfwPollEvents();
}
@@ -163,11 +171,11 @@ fn reloadShader(current: *gl.ShaderProgram, frag_file: fs.File, size: u64) !void
\\ gl_Position = vec4(position, 0, 1);
\\}
;
-
+
if (gl.ShaderProgram.create(vert_source, frag_source[0..length])) |new_program| {
current.destroy();
current.* = new_program;
} else |err| {
- std.debug.warn("Error while reloading shader:{}\n", .{ err });
+ std.debug.warn("Error while reloading shader:{}\n", .{err});
}
}