Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
* float init
* missing simgui_render on example
* refactor cimgui-build - `build.zig`
  • Loading branch information
kassane committed Apr 21, 2024
1 parent e0c7deb commit e0ab669
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 187 deletions.
36 changes: 26 additions & 10 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ pub fn build(b: *Build) !void {
"-w", // warnings as error
// more info: ldc2 -preview=help (list all specs)
"-preview=all",
"--enable-no-nans-fp-math",
},
.d_packages = if (target.result.isWasm()) &[_][]const u8{
b.dependency("wasmd", .{}).path("arsd-webassembly").getPath(b),
Expand Down Expand Up @@ -841,9 +842,9 @@ fn emSdkSetupStep(b: *Build, emsdk: *Build.Dependency) !?*Build.Step.Run {

fn buildImgui(b: *Build, options: LibSokolOptions) !*CompileStep {
const imgui_cpp = b.dependency("imgui", .{});
const imgui_cpp_dir = imgui_cpp.path("").getPath(b);
const imgui_cpp_dir = imgui_cpp.path("");
const cimgui = b.dependency("cimgui", .{});
const cimgui_dir = cimgui.path("").getPath(b);
const cimgui_dir = cimgui.path("");

const libimgui = b.addStaticLibrary(.{
.name = "cimgui",
Expand All @@ -854,8 +855,8 @@ fn buildImgui(b: *Build, options: LibSokolOptions) !*CompileStep {
libimgui.pie = true
else if (libimgui.linkage == .static)
libimgui.root_module.pic = true;
libimgui.addIncludePath(.{ .path = cimgui_dir });
libimgui.addIncludePath(.{ .path = imgui_cpp_dir });
libimgui.addIncludePath(.{ .path = cimgui_dir.getPath(b) });
libimgui.addIncludePath(.{ .path = imgui_cpp_dir.getPath(b) });
libimgui.defineCMacro("IMGUI_DISABLE_OBSOLETE_FUNCTIONS", "1");
if (libimgui.rootModuleTarget().isWasm()) {
// make sure we're building for the wasm32-emscripten target, not wasm32-freestanding
Expand All @@ -870,13 +871,28 @@ fn buildImgui(b: *Build, options: LibSokolOptions) !*CompileStep {
libimgui.defineCMacro("IMGUI_DISABLE_FILE_FUNCTIONS", null);
}
libimgui.addCSourceFiles(.{
.root = cimgui_dir,
.files = &.{
b.pathJoin(&.{ cimgui_dir, "cimgui.cpp" }),
b.pathJoin(&.{ imgui_cpp_dir, "imgui.cpp" }),
b.pathJoin(&.{ imgui_cpp_dir, "imgui_draw.cpp" }),
b.pathJoin(&.{ imgui_cpp_dir, "imgui_demo.cpp" }),
b.pathJoin(&.{ imgui_cpp_dir, "imgui_widgets.cpp" }),
b.pathJoin(&.{ imgui_cpp_dir, "imgui_tables.cpp" }),
"cimgui.cpp",
},
.flags = &.{
"-Wall",
"-Wextra",
"-fno-rtti",
"-fno-exceptions",
"-Wno-unused-parameter",
"-Wno-missing-field-initializers",
"-fno-threadsafe-statics",
},
});
libimgui.addCSourceFiles(.{
.root = imgui_cpp_dir,
.files = &.{
"imgui.cpp",
"imgui_draw.cpp",
"imgui_demo.cpp",
"imgui_widgets.cpp",
"imgui_tables.cpp",
},
.flags = &.{
"-Wall",
Expand Down
8 changes: 5 additions & 3 deletions src/examples/imgui.d
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static State state;
void init()
{
sg.Desc gfx = {
context: sgapp.context(),
environment: sgapp.environment,
logger: {func: &log.slog_func}
};
sg.setup(gfx);
Expand All @@ -46,7 +46,7 @@ void frame()
imgui.simgui_new_frame(&imgui_desc);

/*=== UI CODE STARTS HERE ===*/
const imgui.ImVec2 window_pos = {0,0};
const imgui.ImVec2 window_pos = {10,10};
const imgui.ImVec2 window_pos_pivot = {0,0};
const imgui.ImVec2 window_size = {400, 100};
imgui.igSetNextWindowPos(window_pos, imgui.ImGuiCond_.ImGuiCond_Once, window_pos_pivot);
Expand All @@ -58,7 +58,9 @@ void frame()
imgui.igEnd();
/*=== UI CODE ENDS HERE ===*/

sg.beginDefaultPass(state.pass_action, sapp.width(), sapp.height());
sg.Pass pass = {action: state.pass_action, swapchain: sgapp.swapchain};
sg.beginPass(pass);
imgui.simgui_render();
sg.endPass();
sg.commit();
}
Expand Down
Loading

0 comments on commit e0ab669

Please sign in to comment.