Two triangles
This commit is contained in:
parent
a8dd27f3a4
commit
b4fc2b48d5
20
src/main.zig
20
src/main.zig
@ -9,6 +9,7 @@ var pass_action: sg.PassAction = .{};
|
|||||||
|
|
||||||
const state = struct {
|
const state = struct {
|
||||||
var bind: sg.Bindings = .{};
|
var bind: sg.Bindings = .{};
|
||||||
|
var bind2: sg.Bindings = .{};
|
||||||
var pip: sg.Pipeline = .{};
|
var pip: sg.Pipeline = .{};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -22,13 +23,23 @@ export fn init() void {
|
|||||||
|
|
||||||
std.log.info("Vertex buffers len: {}", .{state.bind.vertex_buffers.len});
|
std.log.info("Vertex buffers len: {}", .{state.bind.vertex_buffers.len});
|
||||||
|
|
||||||
state.bind.vertex_buffers[0] = sg.makeBuffer(.{
|
var triangleVerts = [_]f32{
|
||||||
.data = sg.asRange(&[_]f32{
|
|
||||||
// positions colors
|
// positions colors
|
||||||
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,
|
||||||
}),
|
};
|
||||||
|
|
||||||
|
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 = .{
|
var pip_desc: sg.PipelineDesc = .{
|
||||||
@ -58,9 +69,12 @@ export fn frame() void {
|
|||||||
col.r = @abs(@cos(timef()));
|
col.r = @abs(@cos(timef()));
|
||||||
|
|
||||||
sg.beginPass(.{ .action = pass_action, .swapchain = sokol.glue.swapchain() });
|
sg.beginPass(.{ .action = pass_action, .swapchain = sokol.glue.swapchain() });
|
||||||
|
sg.asRange(3);
|
||||||
sg.applyPipeline(state.pip);
|
sg.applyPipeline(state.pip);
|
||||||
sg.applyBindings(state.bind);
|
sg.applyBindings(state.bind);
|
||||||
sg.draw(0, 3, 1);
|
sg.draw(0, 3, 1);
|
||||||
|
sg.applyBindings(state.bind2);
|
||||||
|
sg.draw(0, 3, 1);
|
||||||
sg.endPass();
|
sg.endPass();
|
||||||
sg.commit();
|
sg.commit();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user