aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/main.zig b/src/main.zig
index 6d70a14..fbe006e 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -118,6 +118,15 @@ pub fn main() !void {
defer control.destroy();
var loops: u8 = 0;
+
+ const stdout = std.fs.File.stdout();
+ var tex_buffer: ?[]u8 = null;
+
+ if (!stdout.isTty()) {
+ tex_buffer = try std.heap.c_allocator.alloc(u8, @intCast(config.width * config.height * 4));
+ }
+ defer if (tex_buffer) |buf| std.heap.c_allocator.free(buf);
+
while (c.glfwWindowShouldClose(window) == c.GL_FALSE) {
c.glfwMakeContextCurrent(window);
@@ -135,7 +144,7 @@ pub fn main() !void {
// control.reload_requested = false;
// }
- {
+ if (control.dirty) {
c.glFinish();
var timer = try std.time.Timer.start();
@@ -144,6 +153,13 @@ pub fn main() !void {
main_program.bind();
constants.normalized_quad.draw();
+
+ if (tex_buffer) |buf| {
+ fbo.read(config.width, config.height, buf);
+ std.debug.print("writing {} bytes\n", .{buf.len});
+ _ = try stdout.write(buf);
+ }
+
fbo.unbind();
c.glFinish();
@@ -152,6 +168,8 @@ pub fn main() !void {
if (loops == 0) {
std.debug.print("\rrendered in {d:.2}ms\n", .{@as(f64, @floatFromInt(fps)) / std.time.ns_per_ms});
}
+
+ control.dirty = false;
}
for (outputs.items, 0..) |output, i| {