jvcleave / ofxImGui

Use ImGui in openFrameworks
300 stars 123 forks source link

Emscripten fix #116

Open Jonathhhan opened 1 year ago

Jonathhhan commented 1 year ago

With adding #include "stack" to ImHelpers.h (and a few small additional changes) it works also with Emscripten.

Daandelange commented 1 year ago

Hey, Thanks for your PR. Have you seen the develop branch ? We're planning to transition to that branch. It should support Emscripten too. I'd love to know if it works on Emscripten.

Jonathhhan commented 1 year ago

@Daandelange I tried the develop branch, and it seems to be more complicated to make it work. First I had to add the GLES includes to EngineOpenFrameworks.h, but then I still get this error:

wasm-ld: error: /home/jonathan/Desktop/of_v20230320_linux64gcc6_release/addons/obj/emscripten/Release/ofxImGui/libs/imgui/backends/imgui_impl_opengl3.o: undefined symbol: glPolygonMode
wasm-ld: error: /home/jonathan/Desktop/of_v20230320_linux64gcc6_release/addons/obj/emscripten/Release/ofxImGui/libs/imgui/backends/imgui_impl_opengl3.o: undefined symbol: glPolygonMode
wasm-ld: error: /home/jonathan/Desktop/of_v20230320_linux64gcc6_release/addons/obj/emscripten/Release/ofxImGui/libs/imgui/backends/imgui_impl_opengl2.o: undefined symbol: glGetTexEnviv
wasm-ld: error: /home/jonathan/Desktop/of_v20230320_linux64gcc6_release/addons/obj/emscripten/Release/ofxImGui/libs/imgui/backends/imgui_impl_opengl2.o: undefined symbol: glPushAttrib
wasm-ld: error: /home/jonathan/Desktop/of_v20230320_linux64gcc6_release/addons/obj/emscripten/Release/ofxImGui/libs/imgui/backends/imgui_impl_opengl2.o: undefined symbol: glTexCoordPointer
wasm-ld: error: /home/jonathan/Desktop/of_v20230320_linux64gcc6_release/addons/obj/emscripten/Release/ofxImGui/libs/imgui/backends/imgui_impl_opengl2.o: undefined symbol: glColorPointer
wasm-ld: error: /home/jonathan/Desktop/of_v20230320_linux64gcc6_release/addons/obj/emscripten/Release/ofxImGui/libs/imgui/backends/imgui_impl_opengl2.o: undefined symbol: glDisableClientState
wasm-ld: error: /home/jonathan/Desktop/of_v20230320_linux64gcc6_release/addons/obj/emscripten/Release/ofxImGui/libs/imgui/backends/imgui_impl_opengl2.o: undefined symbol: glDisableClientState
wasm-ld: error: /home/jonathan/Desktop/of_v20230320_linux64gcc6_release/addons/obj/emscripten/Release/ofxImGui/libs/imgui/backends/imgui_impl_opengl2.o: undefined symbol: glDisableClientState
wasm-ld: error: /home/jonathan/Desktop/of_v20230320_linux64gcc6_release/addons/obj/emscripten/Release/ofxImGui/libs/imgui/backends/imgui_impl_opengl2.o: undefined symbol: glPopMatrix
wasm-ld: error: /home/jonathan/Desktop/of_v20230320_linux64gcc6_release/addons/obj/emscripten/Release/ofxImGui/libs/imgui/backends/imgui_impl_opengl2.o: undefined symbol: glPopMatrix
wasm-ld: error: /home/jonathan/Desktop/of_v20230320_linux64gcc6_release/addons/obj/emscripten/Release/ofxImGui/libs/imgui/backends/imgui_impl_opengl2.o: undefined symbol: glPopAttrib
wasm-ld: error: /home/jonathan/Desktop/of_v20230320_linux64gcc6_release/addons/obj/emscripten/Release/ofxImGui/libs/imgui/backends/imgui_impl_opengl3.o: undefined symbol: glPolygonMode
wasm-ld: error: /home/jonathan/Desktop/of_v20230320_linux64gcc6_release/addons/obj/emscripten/Release/ofxImGui/libs/imgui/backends/imgui_impl_opengl3.o: undefined symbol: glPolygonMode
wasm-ld: error: /home/jonathan/Desktop/of_v20230320_linux64gcc6_release/addons/obj/emscripten/Release/ofxImGui/libs/imgui/backends/imgui_impl_opengl2.o: undefined symbol: glShadeModel
wasm-ld: error: /home/jonathan/Desktop/of_v20230320_linux64gcc6_release/addons/obj/emscripten/Release/ofxImGui/libs/imgui/backends/imgui_impl_opengl2.o: undefined symbol: glTexEnvi
wasm-ld: error: /home/jonathan/Desktop/of_v20230320_linux64gcc6_release/addons/obj/emscripten/Release/ofxImGui/libs/imgui/backends/imgui_impl_opengl2.o: undefined symbol: glEnableClientState
wasm-ld: error: /home/jonathan/Desktop/of_v20230320_linux64gcc6_release/addons/obj/emscripten/Release/ofxImGui/libs/imgui/backends/imgui_impl_opengl2.o: undefined symbol: glEnableClientState
wasm-ld: error: /home/jonathan/Desktop/of_v20230320_linux64gcc6_release/addons/obj/emscripten/Release/ofxImGui/libs/imgui/backends/imgui_impl_opengl2.o: undefined symbol: glEnableClientState
wasm-ld: error: /home/jonathan/Desktop/of_v20230320_linux64gcc6_release/addons/obj/emscripten/Release/ofxImGui/libs/imgui/backends/imgui_impl_opengl2.o: undefined symbol: glDisableClientState
wasm-ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)

But I am sure it will work with the right changes (because it does work well with the master branch). Here you can try the demo example (compiled with my fork of the master branch and the current OF and Emscripten): https://ofximgui.handmadeproductions.de/

Daandelange commented 1 year ago

Hi, thanks for giving it a try. :)
These errors are GLES2 symbols that I bypassed by injecting GLES1 hacks, you probably need that include too, you're probably missing a macro condition to include it. ImGui doesn't support GLES1, OF does.
Weird that imgui_impl_opengl3.cpp also throws one error, I only had them in imgui_impl_opengl2.cpp

Look in ofxImGuiConstants.h if the correct macros are defined. I'll be able to help deeper within a few weeks.

Daandelange commented 2 months ago

Hi, did you make any progress on this ?

Jonathhhan commented 2 months ago

Hi, sorry. I did not make any progress with that. But for another project I created SWIG bindings for ofxImGui (not related to the Emscripten stuff). I will come back to the issue, eventually (I make a short summer programming break at the moment...).

danoli3 commented 2 months ago

I did look into this as I had some GL errors in one of the builds with particular Makefile settings for the new libraries and Version of Emscripten.

If possible ImGui update to latest just out this week and I'll look at the bindings as it solves

Daandelange commented 2 months ago

@danoli3 Would you like me to update ImGui or are you on it ? (see Updating ImGui) Also note that the GLES1 hacks mentioned above are (very) dirty (but they just work) : there could be a better way to do this.

danoli3 commented 2 months ago

Feel free to jump in and update it to the latest, commit any progress if you get stuck but always can look past ES 1 for the moment

Daandelange commented 2 months ago

OK, I just updated ImGui to v 1.91.0 which seems to introduce some glfw+emscripten fixes, is that what you're looking after ?

Jonathhhan commented 2 months ago

I might be a little slow at the moment with programming, because I enjoy the summer, but I will check it soon. Thank you. I will try it in the next days.

Daandelange commented 2 months ago

No hurries, take your time and enjoy ;)