tringle
This commit is contained in:
20
build.zig
20
build.zig
@@ -1,8 +1,9 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const cimgui = @import("cimgui");
|
const cimgui = @import("cimgui");
|
||||||
|
const sokol = @import("sokol");
|
||||||
|
|
||||||
pub fn build(b: *std.Build) void {
|
pub fn build(b: *std.Build) !void {
|
||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
@@ -26,8 +27,23 @@ pub fn build(b: *std.Build) void {
|
|||||||
});
|
});
|
||||||
sokol_dep.artifact("sokol_clib").addIncludePath(cimgui_dep.path(cimgui_conf.include_dir));
|
sokol_dep.artifact("sokol_clib").addIncludePath(cimgui_dep.path(cimgui_conf.include_dir));
|
||||||
|
|
||||||
|
const sokol_mod = sokol_dep.module("sokol");
|
||||||
|
const shdc_dep = sokol_dep.builder.dependency("shdc", .{});
|
||||||
|
|
||||||
|
const shader_mod = try sokol.shdc.createModule(b, "shader", sokol_mod, .{
|
||||||
|
.shdc_dep = shdc_dep,
|
||||||
|
.input = "src/shader.glsl",
|
||||||
|
.output = "shader.zig",
|
||||||
|
.slang = .{
|
||||||
|
.glsl430 = true,
|
||||||
|
.hlsl5 = true,
|
||||||
|
.metal_macos = true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
exe_mod.addImport("cimgui", cimgui_dep.module(cimgui_conf.module_name));
|
exe_mod.addImport("cimgui", cimgui_dep.module(cimgui_conf.module_name));
|
||||||
exe_mod.addImport("sokol", sokol_dep.module("sokol"));
|
exe_mod.addImport("shader", shader_mod);
|
||||||
|
exe_mod.addImport("sokol", sokol_mod);
|
||||||
|
|
||||||
const exe = b.addExecutable(.{
|
const exe = b.addExecutable(.{
|
||||||
.name = "voxel-game",
|
.name = "voxel-game",
|
||||||
|
|||||||
48
src/main.zig
48
src/main.zig
@@ -1,11 +1,13 @@
|
|||||||
const sokol = @import("sokol");
|
const sokol = @import("sokol");
|
||||||
|
const shader = @import("shader");
|
||||||
|
|
||||||
const slog = sokol.log;
|
const slog = sokol.log;
|
||||||
const sg = sokol.gfx;
|
const sg = sokol.gfx;
|
||||||
const sapp = sokol.app;
|
const sapp = sokol.app;
|
||||||
const sglue = sokol.glue;
|
const sglue = sokol.glue;
|
||||||
const simgui = sokol.imgui;
|
const simgui = sokol.imgui;
|
||||||
|
|
||||||
const imgui_pass_action = blk: {
|
const main_action = blk: {
|
||||||
var ret: sg.PassAction = .{};
|
var ret: sg.PassAction = .{};
|
||||||
|
|
||||||
ret.colors[0] = .{
|
ret.colors[0] = .{
|
||||||
@@ -16,6 +18,19 @@ const imgui_pass_action = blk: {
|
|||||||
break :blk ret;
|
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 {
|
fn init() callconv(.c) void {
|
||||||
sg.setup(.{
|
sg.setup(.{
|
||||||
.environment = sglue.environment(),
|
.environment = sglue.environment(),
|
||||||
@@ -25,6 +40,24 @@ fn init() callconv(.c) void {
|
|||||||
simgui.setup(.{
|
simgui.setup(.{
|
||||||
.logger = .{ .func = slog.func },
|
.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 {
|
fn deinit() callconv(.c) void {
|
||||||
@@ -40,10 +73,21 @@ fn frame() callconv(.c) void {
|
|||||||
.dpi_scale = sapp.dpiScale(),
|
.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 ---
|
// --- IMGUI PASS ---
|
||||||
|
|
||||||
sg.beginPass(.{
|
sg.beginPass(.{
|
||||||
.action = imgui_pass_action,
|
.action = imgui_action,
|
||||||
.swapchain = sglue.swapchain(),
|
.swapchain = sglue.swapchain(),
|
||||||
});
|
});
|
||||||
simgui.render();
|
simgui.render();
|
||||||
|
|||||||
23
src/shader.glsl
Normal file
23
src/shader.glsl
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
@vs vert
|
||||||
|
in vec4 position_CS;
|
||||||
|
in vec4 color;
|
||||||
|
|
||||||
|
out vec4 varColor;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_Position = position_CS;
|
||||||
|
varColor = color;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@fs frag
|
||||||
|
in vec4 varColor;
|
||||||
|
|
||||||
|
out vec4 fragColor;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
fragColor = varColor;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@program program vert frag
|
||||||
Reference in New Issue
Block a user