Two triangles

This commit is contained in:
nothke 2024-06-11 15:03:05 +02:00
parent a8dd27f3a4
commit b4fc2b48d5
1 changed files with 20 additions and 6 deletions

View File

@ -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});
state.bind.vertex_buffers[0] = sg.makeBuffer(.{
.data = sg.asRange(&[_]f32{
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(&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();
}