Drawing a quad

This commit is contained in:
nothke 2024-06-12 00:43:10 +02:00
parent d8f5c9bb61
commit 5ecc42ab89
2 changed files with 13 additions and 3 deletions

View File

@ -11,6 +11,7 @@ const state = struct {
var bind: sg.Bindings = .{}; var bind: sg.Bindings = .{};
var pip: sg.Pipeline = .{}; var pip: sg.Pipeline = .{};
var vsParams: shader.FsParams = .{ .offset = .{ 0, 0, 0 } }; var vsParams: shader.FsParams = .{ .offset = .{ 0, 0, 0 } };
var indexCount: u16 = 0;
}; };
export fn init() void { 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.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, 1.0, 0.0, 1.0,
-0.5, -0.5, 0.5, 0.0, 0.0, 1.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(.{ state.bind.vertex_buffers[0] = sg.makeBuffer(.{
.data = sg.asRange(&triangleVerts), .data = sg.asRange(&triangleVerts),
}); });
const indexBuffer = [_]u16{
0, 1, 2,
0, 3, 1,
};
state.indexCount = indexBuffer.len;
state.bind.index_buffer = sg.makeBuffer(.{ state.bind.index_buffer = sg.makeBuffer(.{
.type = .INDEXBUFFER, .type = .INDEXBUFFER,
.data = sg.asRange(&[_]u16{ 0, 1, 2 }), .data = sg.asRange(&indexBuffer),
}); });
var pip_desc: sg.PipelineDesc = .{ var pip_desc: sg.PipelineDesc = .{
@ -71,7 +80,7 @@ export fn frame() void {
state.vsParams.offset[0] = col.r; state.vsParams.offset[0] = col.r;
sg.applyUniforms(.FS, shader.SLOT_fs_params, sg.asRange(&state.vsParams)); sg.applyUniforms(.FS, shader.SLOT_fs_params, sg.asRange(&state.vsParams));
sg.applyBindings(state.bind); sg.applyBindings(state.bind);
sg.draw(0, 3, 1); sg.draw(0, state.indexCount, 1);
sg.endPass(); sg.endPass();
sg.commit(); sg.commit();

View File

@ -9,7 +9,8 @@ Today:
☐ Guide through the code ☐ Guide through the code
Draw a circle!: 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 ☐ Create a circle vertices
☐ Draw the circle ☐ Draw the circle
☐ Make the circle move with uniforms ☐ Make the circle move with uniforms