Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImGui Support #10

Closed
Tracked by #3
kassane opened this issue Jan 11, 2024 · 13 comments · Fixed by #23
Closed
Tracked by #3

ImGui Support #10

kassane opened this issue Jan 11, 2024 · 13 comments · Fixed by #23
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@kassane
Copy link
Owner

kassane commented Jan 11, 2024

There are some Sokol examples to be ported that use ImGui.

Since only build.zig is available, zig-pkg will be used to download D packages.

sokol-d/build.zig.zon

Lines 4 to 10 in 43d371b

.dependencies = .{
// TODO
// .@"bindbc-imgui" = .{
// .url = "git+https://github.com/BindBC/bindbc-imgui#63cf88e1ab3981794d2e17d2c4a30d1ac340b148",
// .hash = "1220194ac6476adaed11b30299a8abdd593eb7ae6d368bf6832d7fe6a604f12cae4f",
// },
},

D binding

References

@kassane kassane added enhancement New feature or request help wanted Extra attention is needed labels Jan 11, 2024
@kassane kassane mentioned this issue Jan 11, 2024
13 tasks
kassane added a commit that referenced this issue Jan 13, 2024
kassane added a commit that referenced this issue Jan 15, 2024
kassane added a commit that referenced this issue Jan 16, 2024
@kassane
Copy link
Owner Author

kassane commented Jan 16, 2024

@floooh
Copy link
Collaborator

floooh commented Jan 17, 2024

Imgui support in the bindings is currently a bit messy. sokol_imgui.h currently isn't included in the "original" bindings (Zig, Nim, Odin), but was only added by the contributed Rust bindings (but went stale there).

One reason (which tbh doesn't make a lot of sense) was that I didn't want to have any sort of external dependency in the bindings, e.g. there couldn't be an imgui example (such an example would need to live in a separate repo). But this also means that any problems in the sokol_imgui.h bindings wouldn't be caught by running the tests (since those just compile the included samples).

I guess it does make sense to include sokol_imgui.h in all bindings, even without an integrated sample.

Just some sort of braindump from my side ;)

@kassane
Copy link
Owner Author

kassane commented Jan 22, 2024

After rebasing the ImGui branch with wasm support and some fixes.
The ImGui library built by zig gives an error about not having found 'assert.h' which is only needed by ImGui.

I also tried to use IM_ASSERT macro define to replace C assert, but it gives several errors in the API.
I don't know how this custom assert works since I haven't seen it in any examples.

install
+- emcc
   +- mrt
      +- zig build-lib sokol ReleaseSmall wasm32-emscripten
         +- zig build-lib cimgui ReleaseSmall wasm32-emscripten 6 errors
/home/runner/.cache/zig/p/12202af0db41b79a4c7904950269b5e33b7d48f50aae042e334cb8d717a5a2caf48d/imgui.h:84:10: error: 'assert.h' file not found
/home/runner/.cache/zig/p/1220e6183fb9559dbfafe58d7fab20f1c330bee32342205815aa10553134ff9f9302/cimgui.cpp:13:10: note: in file included from /home/runner/.cache/zig/p/1220e6183fb9559dbfafe58d7fab20f1c330bee32342205815aa10553134ff9f9302/cimgui.cpp:13:
/home/runner/.cache/zig/p/12202af0db41b79a4c7904950269b5e33b7d48f50aae042e334cb8d717a5a2caf48d/imgui.h:84:10: error: 'assert.h' file not found
/home/runner/.cache/zig/p/12202af0db41b79a4c7904950269b5e33b7d48f50aae042e334cb8d717a5a2caf48d/imgui_demo.cpp:96:10: note: in file included from /home/runner/.cache/zig/p/12202af0db41b79a4c7904950269b5e33b7d48f50aae042e334cb8d717a5a2caf48d/imgui_demo.cpp:96:
/home/runner/.cache/zig/p/12202af0db41b79a4c7904950269b5e33b7d48f50aae042e334cb8d717a5a2caf48d/imgui.h:84:10: error: 'assert.h' file not found
/home/runner/.cache/zig/p/12202af0db41b79a4c7904950269b5e33b7d48f50aae042e334cb8d717a5a2caf48d/imgui_draw.cpp:33:10: note: in file included from /home/runner/.cache/zig/p/12202af0db41b79a4c7904950269b5e33b7d48f50aae042e334cb8d717a5a2caf48d/imgui_draw.cpp:33:
[...]

Edit

It may be necessary, try build ImGui using emcc/emc++.

@kassane
Copy link
Owner Author

kassane commented Feb 2, 2024

updated branch e new issue detected on imgui:

 zig build run-imgui
/home/kassane/sokol-d/src/examples/imgui.d(25,14): `state` is thread local
imgui: /home/kassane/.cache/zig/p/12202af0db41b79a4c7904950269b5e33b7d48f50aae042e334cb8d717a5a2caf48d/imgui.cpp:9526: void ImGui::ErrorCheckNewFrameSanityChecks(): Assertion `(g.FrameCount == 0 || g.FrameCountEnded == g.FrameCount) && "Forgot to call Render() or EndFrame() at the end of the previous frame?"' failed.
run-imgui
└─ run /home/kassane/sokol-d/zig-out/bin/imgui failure

@floooh
Copy link
Collaborator

floooh commented Feb 20, 2024

Btw, I tinkered a bit with imgui-support in the Rust bindings:

floooh/sokol@b728ee6

Note how I'm adding the sokol_imgui.h header only to the Rust bindings generation.

I ignored the simgui_add_key_event function because the function signature is not yet supported by the bindings generator and it's a fairly esoteric function.

I also had to remove the sokol_gfx_imgui.h bindings, because this has a union in the public API, which isn't supported either.

Ultimately I didn't get it working, because the Rust imgui bindings (imgui_sys) are stuck on an older ImGui version which the sokol_imgui.h header doesn't support anymore.

I'm now also slowly seeing the light at the end of the rabbit hole I'm currently in (floooh/sokol#985) after that hopefully have a bit of time for looking into the bindings before the next 'big thing' (storage buffers).

@floooh
Copy link
Collaborator

floooh commented Mar 1, 2024

Btw 2: I have removed the imgui-stuff in the Rust bindings for now. There was a cimgui git submodule in the examples which caused trouble in the GH Actions jobs (artifacts with git submodules included fail to download in a Windows job). I didn't feel like investigating this and delay the render-pass-cleanup merge. If we add sokol_imgui.h bindings and examples we should do it in a way that works for all bindings.

@kassane
Copy link
Owner Author

kassane commented Apr 21, 2024

WiP - some fixes e0ab669
image

@kassane
Copy link
Owner Author

kassane commented Apr 21, 2024

The ImGui library built by zig gives an error about not having found 'assert.h' which is only needed by ImGui.

Which cflag/cdefine solves assert.h in wasm?

Just the first build gives an error with emsdk. If rebuilt no error is returned. Maybe, need run emsdk_install before ldc + zig to fix!!

sokol-d/build.zig

Lines 74 to 77 in 1d1fc58

// one-time setup of Emscripten SDK
if (try emSdkSetupStep(b, options.emsdk.?)) |emsdk_setup| {
lib.step.dependOn(&emsdk_setup.step);
}


image

@kassane
Copy link
Owner Author

kassane commented May 12, 2024

new commit: 9198de3 broken imgui branch

S3, SOKOL_D3D11, SOKOL_METAL, SOKOL_WGPU or SOKOL_DUMMY_BACKEND!"
#error "Please define one of SOKOL_GLCORE33, SOKOL_GLES3, SOKOL_D3D11, SOKOL_METAL, SOKOL_WGPU or SOKOL_DUMMY_BACKEND!"
 ^
/home/kassane/sokol-d/src/sokol/c/sokol_imgui.c:9:10: note: in file included from /home/kassane/sokol-d/src/sokol/c/sokol_imgui.c:9:
#include "sokol_imgui.h"
         ^
/home/kassane/sokol-d/src/sokol/c/sokol_imgui.h:2270:30: error: use of undeclared identifier '_simgui_vs_source_dummy'
        shd_desc.vs.source = _simgui_vs_source_dummy;

@kassane
Copy link
Owner Author

kassane commented May 31, 2024

@floooh
Copy link
Collaborator

floooh commented Jun 1, 2024

Btw the tricky part is to inject a cimgui header search path into the sokol C libary build without adding a dependency to cimgui/Dear ImGui to the sokol-zig package. So the other important half is here in the example project:

https://github.com/floooh/sokol-zig-imgui-sample/blob/main/build.zig

@kassane
Copy link
Owner Author

kassane commented Jun 1, 2024

Btw the tricky part is to inject a cimgui header search path into the sokol C libary build without adding a dependency to cimgui/Dear ImGui to the sokol-zig package. So the other important half is here in the example project:

https://github.com/floooh/sokol-zig-imgui-sample/blob/main/build.zig

I see. However, the writefiles stepwait breaks my build.
I tried adapting buildimgui and later copying its configuration and still got the same step error.

@kassane
Copy link
Owner Author

kassane commented Jun 1, 2024

How to skip IMGUI assert on wasm target?

/home/kassane/.cache/zig/p/122072b125179c7cbdbbee8fa81d22a1050a950ad61cfeefee8dc0dca5423b5d05b9/imgui.h:88:10: error: 'assert.h' file not found
#include <assert.h>
         ^~~~~~~~~~~
/home/kassane/.cache/zig/p/122072b125179c7cbdbbee8fa81d22a1050a950ad61cfeefee8dc0dca5423b5d05b9/imgui_tables.cpp:198:10: note: in file included from /home/kassane/.cache/zig/p/122072b125179c7cbdbbee8fa81d22a1050a950ad61cfeefee8dc0dca5423b5d05b9/imgui_tables.cpp:198:
#include "imgui.h"

Add -DIM_ASSERT!!

How add step on *Dependency type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants