From 5ecc42ab89e4ee162b18f07b4aa63f4d993e15da Mon Sep 17 00:00:00 2001 From: nothke Date: Wed, 12 Jun 2024 00:43:10 +0200 Subject: [PATCH] Drawing a quad --- src/main.zig | 13 +++++++++++-- todo.todo | 3 ++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main.zig b/src/main.zig index 1178943..79f6e74 100644 --- a/src/main.zig +++ b/src/main.zig @@ -11,6 +11,7 @@ const state = struct { var bind: sg.Bindings = .{}; var pip: sg.Pipeline = .{}; var vsParams: shader.FsParams = .{ .offset = .{ 0, 0, 0 } }; + var indexCount: u16 = 0; }; export fn init() void { @@ -28,15 +29,23 @@ export fn init() void { 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, + 0.7, 0.5, 0.5, 0.0, 1.0, 0.0, 1.0, }; state.bind.vertex_buffers[0] = sg.makeBuffer(.{ .data = sg.asRange(&triangleVerts), }); + const indexBuffer = [_]u16{ + 0, 1, 2, + 0, 3, 1, + }; + + state.indexCount = indexBuffer.len; + state.bind.index_buffer = sg.makeBuffer(.{ .type = .INDEXBUFFER, - .data = sg.asRange(&[_]u16{ 0, 1, 2 }), + .data = sg.asRange(&indexBuffer), }); var pip_desc: sg.PipelineDesc = .{ @@ -71,7 +80,7 @@ export fn frame() void { state.vsParams.offset[0] = col.r; sg.applyUniforms(.FS, shader.SLOT_fs_params, sg.asRange(&state.vsParams)); sg.applyBindings(state.bind); - sg.draw(0, 3, 1); + sg.draw(0, state.indexCount, 1); sg.endPass(); sg.commit(); diff --git a/todo.todo b/todo.todo index 17757e4..a8ef412 100644 --- a/todo.todo +++ b/todo.todo @@ -9,7 +9,8 @@ Today: ☐ Guide through the code Draw a circle!: - ☐ Draw indices instead of triangle elements + ✔ Draw indices instead of triangle elements @done(24-06-12 00:29) + ☐ Quad ☐ Create a circle vertices ☐ Draw the circle ☐ Make the circle move with uniforms \ No newline at end of file