treesummaryrefslogcommitdiff
diff options
context:
space:
mode:
authorPatrick2026-09-27 10:57:03 +0200
committerPatrick2026-09-27 10:57:03 +0200
commitc511ae90162f506f34ca0b98732577dc688ebcca (patch)
tree218eab224b41aac86948c0d03de612f80c406e91
parenta58717ae1a2451635c7dee0970e6ee82b9cb4ac2 (diff)
downloadsg3-main.tar.gz
sg3-main.zip
initial stateHEADmain
-rw-r--r--build.zig.zon15
-rw-r--r--flake.nix10
-rw-r--r--src/main.zig50
-rw-r--r--src/shaders/main.glsl21
4 files changed, 64 insertions, 32 deletions
diff --git a/build.zig.zon b/build.zig.zon
index f7cdaf4..91f89d8 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -2,7 +2,7 @@
.name = .sporegirl3,
.version = "0.0.1",
.minimum_zig_version = "0.16.0-dev.1484+d0ba6642b",
- .paths = .{ "src/main.zig", "build.zig", "build.zig.zon" },
+ .paths = .{ "src/main.zig", "src/shaders/main.glsl", "build.zig", "build.zig.zon" },
.fingerprint = 0x688392934479299d,
.dependencies = .{
.emsdk = .{
@@ -13,13 +13,14 @@
.url = "git+https://github.com/floooh/sokol-tools-bin#6801e61ab7ea64dd9369ae9ff2f46d20c61fc655",
.hash = "sokolshdc-0.1.0-r2KZDj2ESgPeSsOrxWqONyemz4-250cFO8ZhXkEs4DrZ",
},
- .sokol = .{
- .url = "git+https://github.com/floooh/sokol-zig?ref=zig-0.16.0#54776d69dac1650221a84191a07269fc4e1e82cd",
- .hash = "sokol-0.1.0-pb1HKxTaNgA8rXBh41wxEucgmR4YPuoOXGeXbFyGPvTK",
- },
.cimgui = .{
- .url = "git+https://github.com/floooh/dcimgui#e2f0e0d93adec02743c55940be23ffe286e857f7",
- .hash = "cimgui-0.1.0-44ClkR8dmgDqqnfloyLE1bUAtl4zSKTT1wxaHSEC0ikV",
+ .path = "deps/dcimgui",
+ // .url = "git+https://github.com/floooh/dcimgui#e2f0e0d93adec02743c55940be23ffe286e857f7",
+ // .hash = "cimgui-0.1.0-44ClkR8dmgDqqnfloyLE1bUAtl4zSKTT1wxaHSEC0ikV",
+ },
+ .sokol = .{
+ .url = "git+https://github.com/floooh/sokol-zig#ff40f04d4f51c73b2bf460d87fd2d7aa0dedc22f",
+ .hash = "sokol-0.1.0-pb1HKygbQQCINV-qSe4SFm92QWaT_95VpWTJkwYqzOrX",
},
},
}
diff --git a/flake.nix b/flake.nix
index 5cd834c..2be7156 100644
--- a/flake.nix
+++ b/flake.nix
@@ -16,9 +16,13 @@
nixpkgs.legacyPackages;
in {
devShells = forAllSystems (pkgs: zig: {
- default = pkgs.mkShellNoCC {
- packages = [pkgs.bash pkgs.tmux zig zig.zls];
+ default = pkgs.mkShell {
+ packages = [
+ pkgs.bash pkgs.tmux zig zig.zls
+ pkgs.alsa-lib pkgs.libGL pkgs.libx11 pkgs.libxi pkgs.libxcursor
+ ];
shellHook = ''
+ export LD_LIBRARY_PATH="${pkgs.alsa-lib}/lib:$LD_LIBRARY_PATH"
tmux set-option -g default-shell '${pkgs.bashInteractive}/bin/bash' ';' new-session -s sporegirl
exit
'';
@@ -31,7 +35,7 @@
version = "0.0.0";
src = ./.;
zigReleaseMode = "fast";
- # depsHash = "<replace this with the hash Nix provides in its error message>"
+ depsHash = "sha256-MtecLHVBg7fuoDJt6nwlq1pChLZqBEPqSK1WI76ruFs";
};
});
};
diff --git a/src/main.zig b/src/main.zig
index 4c6d98a..9f68540 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -9,8 +9,9 @@ const slog = sokol.log;
const sg = sokol.gfx;
const sapp = sokol.app;
const sglue = sokol.glue;
-const imgui = sokol.imgui;
-const appimgui = sokol.appimgui;
+const simgui = sokol.imgui;
+const sappimgui = sokol.appimgui;
+const ig = @import("cimgui_docking");
const vec3 = @import("math.zig").Vec3;
const mat4 = @import("math.zig").Mat4;
const shd = @import("shaders/main.glsl.zig");
@@ -20,6 +21,8 @@ const state = struct {
var pass_action: sg.PassAction = .{};
var pip: sg.Pipeline = .{};
var bind: sg.Bindings = .{};
+ var vs: shd.VsParams = .{.position = .{0,0}};
+ var fs: shd.FsParams = .{.color = .{1,0,0,1}};
};
};
@@ -29,16 +32,21 @@ export fn init() void {
.logger = .{ .func = slog.func },
});
- imgui.setup(.{});
- appimgui.setup();
+ simgui.setup(.{});
+ sappimgui.setup();
+ ig.igGetIO().*.ConfigFlags |= ig.ImGuiConfigFlags_DockingEnable;
// default pass action: clear to blue-ish
state.display.pass_action.colors[0] = .{
.load_action = .CLEAR,
- .clear_value = .{ .r = 0.25, .g = 0.45, .b = 0.65, .a = 1.0 },
+ .clear_value = .{ .r = 1, .g = 0, .b = 0, .a = 1.0 },
};
- const vbuf = sg.makeBuffer(.{});
+ const vbuf = sg.makeBuffer(.{.data = sg.asRange(&[6]f32 {
+ -1.0, -1.0,
+ -1.0, 3.0,
+ 3.0, -1.0,
+ })});
state.display.bind.vertex_buffers[0] = vbuf;
// shader and pipeline object for the default render pass
@@ -46,10 +54,9 @@ export fn init() void {
.shader = sg.makeShader(shd.offscreenShaderDesc(sg.queryBackend())),
.layout = init: {
var l = sg.VertexLayoutState{};
- l.attrs[shd.ATTR_offscreen_position] = .{};
+ l.attrs[shd.ATTR_offscreen_vpos] = .{ .format = .FLOAT2 };
break :init l;
},
- .index_type = .UINT16,
.cull_mode = .BACK,
.depth = .{
.compare = .LESS_EQUAL,
@@ -59,25 +66,46 @@ export fn init() void {
}
export fn event(ev: [*c]const sapp.Event) void {
- appimgui.trackEvent(ev.*);
+ sappimgui.trackEvent(ev.*);
+ // forward input events to sokol-imgui
+ _ = simgui.handleEvent(ev.*);
}
export fn frame() void {
+ // call simgui.newFrame() before any ImGui calls
+ simgui.newFrame(.{
+ .width = sapp.width(),
+ .height = sapp.height(),
+ .delta_time = sapp.frameDuration(),
+ .dpi_scale = sapp.dpiScale(),
+ });
+ sappimgui.trackFrame();
+
// const dt: f32 = @floatCast(sapp.frameDuration() * 60);
// const aspect = sapp.widthf() / sapp.heightf();
+
+ if (ig.igBegin("abc", null, 0))
+ {
+ _ = ig.igDragFloat2("position", &state.display.vs.position);
+ _ = ig.igColorEdit4("color", &state.display.fs.color, 0);
+ ig.igEnd();
+ }
sg.beginPass(.{ .action = state.display.pass_action, .swapchain = sglue.swapchain() });
sg.applyPipeline(state.display.pip);
sg.applyBindings(state.display.bind);
+ sg.applyUniforms(shd.UB_vs_params, sg.asRange(&state.display.vs));
+ sg.applyUniforms(shd.UB_fs_params, sg.asRange(&state.display.fs));
sg.draw(0, 3, 1);
+ simgui.render();
sg.endPass();
sg.commit();
}
export fn cleanup() void {
- appimgui.shutdown();
- imgui.shutdown();
+ sappimgui.shutdown();
+ simgui.shutdown();
sg.shutdown();
}
diff --git a/src/shaders/main.glsl b/src/shaders/main.glsl
index 48de990..4e2d4ea 100644
--- a/src/shaders/main.glsl
+++ b/src/shaders/main.glsl
@@ -4,29 +4,28 @@
@header const m = @import("../math.zig")
@ctype mat4 m.Mat4
-// shared code for all shaders
-@block uniforms
-layout(binding=0) uniform vs_params {
- mat4 mvp;
-};
-@end
-
// offscreen rendering shaders
@vs vs_offscreen
-@include_block uniforms
+layout(binding=0) uniform vs_params {
+ vec2 position;
+};
-in vec2 position;
+in vec2 vpos;
void main() {
- gl_Position = vec4(position, 0, 1);
+ gl_Position = vec4(vpos + position, 0, 1);
}
@end
@fs fs_offscreen
+layout(binding=1) uniform fs_params {
+ vec4 color;
+};
+
out vec4 frag_color;
void main() {
- frag_color = vec4(1.0, 0.5, 1.0, 1.0);
+ frag_color = color;
}
@end