From b4fc2b48d515708a92f02d9c75ce77d18b0f7d4f Mon Sep 17 00:00:00 2001 From: nothke Date: Tue, 11 Jun 2024 15:03:05 +0200 Subject: [PATCH] Two triangles --- src/main.zig | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main.zig b/src/main.zig index 5ccdd5c..28b8fb3 100644 --- a/src/main.zig +++ b/src/main.zig @@ -9,6 +9,7 @@ var pass_action: sg.PassAction = .{}; const state = struct { var bind: sg.Bindings = .{}; + var bind2: sg.Bindings = .{}; var pip: sg.Pipeline = .{}; }; @@ -22,13 +23,23 @@ export fn init() void { std.log.info("Vertex buffers len: {}", .{state.bind.vertex_buffers.len}); + var triangleVerts = [_]f32{ + // positions colors + 0.0, 0.5, 0.5, 1.0, 0.0, 0.0, 1.0, + 0.5, -0.5, 0.5, 0.0, 1.0, 0.0, 1.0, + -0.5, -0.5, 0.5, 0.0, 0.0, 1.0, 1.0, + }; + state.bind.vertex_buffers[0] = sg.makeBuffer(.{ - .data = sg.asRange(&[_]f32{ - // positions colors - 0.0, 0.5, 0.5, 1.0, 0.0, 0.0, 1.0, - 0.5, -0.5, 0.5, 0.0, 1.0, 0.0, 1.0, - -0.5, -0.5, 0.5, 0.0, 0.0, 1.0, 1.0, - }), + .data = sg.asRange(&triangleVerts), + }); + + for (&triangleVerts) |*vert| { + vert.* += 0.2; + } + + state.bind2.vertex_buffers[0] = sg.makeBuffer(.{ + .data = sg.asRange(&triangleVerts), }); var pip_desc: sg.PipelineDesc = .{ @@ -58,9 +69,12 @@ export fn frame() void { col.r = @abs(@cos(timef())); sg.beginPass(.{ .action = pass_action, .swapchain = sokol.glue.swapchain() }); + sg.asRange(3); sg.applyPipeline(state.pip); sg.applyBindings(state.bind); sg.draw(0, 3, 1); + sg.applyBindings(state.bind2); + sg.draw(0, 3, 1); sg.endPass(); sg.commit(); }