tringle
This commit is contained in:
48
src/main.zig
48
src/main.zig
@@ -1,11 +1,13 @@
|
||||
const sokol = @import("sokol");
|
||||
const shader = @import("shader");
|
||||
|
||||
const slog = sokol.log;
|
||||
const sg = sokol.gfx;
|
||||
const sapp = sokol.app;
|
||||
const sglue = sokol.glue;
|
||||
const simgui = sokol.imgui;
|
||||
|
||||
const imgui_pass_action = blk: {
|
||||
const main_action = blk: {
|
||||
var ret: sg.PassAction = .{};
|
||||
|
||||
ret.colors[0] = .{
|
||||
@@ -16,6 +18,19 @@ const imgui_pass_action = blk: {
|
||||
break :blk ret;
|
||||
};
|
||||
|
||||
const imgui_action = blk: {
|
||||
var ret: sg.PassAction = .{};
|
||||
|
||||
ret.colors[0] = .{
|
||||
.load_action = .LOAD,
|
||||
};
|
||||
|
||||
break :blk ret;
|
||||
};
|
||||
|
||||
var bindings: sg.Bindings = .{};
|
||||
var pipeline: sg.Pipeline = .{};
|
||||
|
||||
fn init() callconv(.c) void {
|
||||
sg.setup(.{
|
||||
.environment = sglue.environment(),
|
||||
@@ -25,6 +40,24 @@ fn init() callconv(.c) void {
|
||||
simgui.setup(.{
|
||||
.logger = .{ .func = slog.func },
|
||||
});
|
||||
|
||||
bindings.vertex_buffers[0] = sg.makeBuffer(.{
|
||||
.data = sg.asRange(&[_]f32{
|
||||
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,
|
||||
}),
|
||||
});
|
||||
|
||||
pipeline = sg.makePipeline(.{
|
||||
.shader = sg.makeShader(shader.programShaderDesc(sg.queryBackend())),
|
||||
.layout = blk: {
|
||||
var ret: sg.VertexLayoutState = .{};
|
||||
ret.attrs[shader.ATTR_program_position_CS].format = .FLOAT3;
|
||||
ret.attrs[shader.ATTR_program_color].format = .FLOAT4;
|
||||
break :blk ret;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
fn deinit() callconv(.c) void {
|
||||
@@ -40,10 +73,21 @@ fn frame() callconv(.c) void {
|
||||
.dpi_scale = sapp.dpiScale(),
|
||||
});
|
||||
|
||||
// --- MAIN PASS ---
|
||||
|
||||
sg.beginPass(.{
|
||||
.action = main_action,
|
||||
.swapchain = sglue.swapchain(),
|
||||
});
|
||||
sg.applyPipeline(pipeline);
|
||||
sg.applyBindings(bindings);
|
||||
sg.draw(0, 3, 1);
|
||||
sg.endPass();
|
||||
|
||||
// --- IMGUI PASS ---
|
||||
|
||||
sg.beginPass(.{
|
||||
.action = imgui_pass_action,
|
||||
.action = imgui_action,
|
||||
.swapchain = sglue.swapchain(),
|
||||
});
|
||||
simgui.render();
|
||||
|
||||
Reference in New Issue
Block a user