-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Android + OpenGL ES 3 Example #421
base: master
Are you sure you want to change the base?
Conversation
Thanks! Will look at it when I have time. |
Hi guys I cannot find the android example in the repository. Can someone share it please? |
Search for "Android" on github I believe there is (unsupported) example for it.
|
@sabotage3d here is the link to my branch. It's a very quick example, as the GUI itself is not tailored for mobile (meaning you won't really have much fun typing stuff in or selecting the widgets). |
hello, |
@kingofoz dear imgui is completely system agnostic and works everywhere. You just need to wire inputs and render textures triangles, which all Android devices are able to. |
If interested, I'm working on a jvm port |
What's the current status of this pr? |
@ice1000 This is too old, has too many unrelated and unjustified files*, and would need to be rewritten for the refactored examples. Essentially the core of it is just SDL + OpenGL so we could adapt the existing example e.g. example_sdl_opengl3 and finish adapting the renderer (#1941,#1900,#336), or create a new project example_android_sdl_opengl3/main.cpp using existing bindings if needed. * things like that and other files which probably have no reason to be here. |
People coming to this link in 2018: An actual Android example will minimum cruft/bloat would be nice. |
I'm going to play around and see if I can come up with something that works better on mobile and doesn't have to rely on Android Studio if that's possible. Update: I'm having some trouble minimizing the project structure. Right now it relies on using Android Studio to build the APK file, and the SDL library for the foundation. My problem at the moment is that I don't know how to shrink the size of the Android Studio project or how to build an APK file without Android Studio and export it to the device. I was thinking of trying to run a script that pulls down a project template from the web and pasting in the ImGui/Main.cpp files but I don't know if that's the right approach or where to find a project template. Another idea I had, is creating a JS module using Emscripten and then using React Native to load the module and pass over the GL context or something, but I think that may be even more complicated and unnecessary. |
@zmertens Tests and Android Studio config files can be removed. Resources can be removed, icons can be removed. |
.gradle is also unnecessary. |
@ice1000 Good idea. I really would miss the launcher icon but it's no biggy. I figured out that with the recent SDL2-2.0.9 that you can just use the command line to build the Android project, so Android Studio isn't even required but it does make things easier. I started to put together a BASH script which pulls down SDL into the I updated the The last thing I think to make it a minimal and complete example is to make it more mobile friendly. I figure I can look at the |
the ios example is inside metal one |
I think I have minimized the project structure without making it too complicated. Here are some important notes on the progress:
The example itself is coming along nicely I think. I'm adapting a Julia fractal example from OpenGL Superbible. Right now there's no touch input though, and I'm not sure why, so I'm working on that. Once I have that I'll update the GUI itself. It will probably be a simple overlay that can be minimized in some way. |
examples/example_android_sdl_gles3/app/jni/src/DearImGuiDemo.cpp
Outdated
Show resolved
Hide resolved
The Julia Fractal code is also unnecessary. It is best to model this as close as possible to the existing example (down to the filenames/commments) |
I have updated the code and it's now working like the original PR with minimal files, current imgui and impl files (on my device: MotoG3, Android 6.0 (Nougat). I haven't done any testing on iOS.
@ice1000 Do you know if its possible to change the position of the demo window? It looks hardcoded in the // We specify a default position/size in case there's no data in the .ini file. Typically this isn't required! We only do it to make the Demo applications a little more welcoming.
ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(550, 680), ImGuiCond_FirstUseEver); |
…d iOS (like Emscripten). (#421)
First off, sincere apologies for not investigating this PR further when you made and updated it. Android being unknown territory for me doesn't help but shouldn't be an excuse, especially as you made the effort to vastly improve it from the first draft. Through #3446 we added a native Android backend and an example accordingly. If you think there's value in this PR in light to #3446, may I suggest you squash and force-push it into a single commit (rather than the current 69 commits) so at least it becomes a reference for other users. It is already pretty self contained since you refactored it so I don't imagine there will be any conflict involved. I would also take the occasion to rename the folder to One thing to consider that may be interestingly healthier is, can we come up with a path where the existing examples that use Android-friendly tech (such as example_sdl_opengl3 or even example_sdl_vulkan) be made to work with Android?
Thank you for the amazing show of patience (I'm absolutely certain this PR has been useful to other as it has been linked from the wiki for a long time) |
0c1e5bd
to
bb6a60b
Compare
8b83e0a
to
d735066
Compare
b3b85d8
to
0755767
Compare
c817acb
to
8d39063
Compare
Hello @zmertens, nice to see this branch being updated :) AFAIK your commit using regular backend would be the preferred solution nowadays (tho you can keep them in backends/ and not make local copies in example). With the current state of it your attempt to use SDL3+GL on Android may ideally be reduced into a build script for the existing example_sdl3_opengl3/ example? If you move your stuff there we can potentially better visualize the changes (if any) required to provide this build script. This is essentially same as suggested in #421 (comment) right now we every files being copy of an existing file we can't easily tell the difference. If you move them back to existing files and folder we would be able to. |
bbf0f0e
to
9f72e50
Compare
Hi @ocornut , thanks for the recent review, I did some squashing and reduced the repo to 3 files and the SDL3 submodule. I kept the SDL3 submodule because it has the There aren't many differences between Please let me know if this direction looks good or not :). |
The direction that would be good is not creating a new example and adding build scripts to an existing one, if that makes sense and is not an overly complicated build script. |
9b478f5
to
a16f05c
Compare
119579a
to
127d768
Compare
I did some hacking and I think I got the current Android example working with SDL3 after changing
|
127d768
to
d62a60a
Compare
I think this can work as a single Makefile, similar to most of the other ImGui examples here. I can explain the new updates here: Get SDL latest from the main branch and unpack it and then prepare the build script bundled with SDL.
This step requires Python3 and it does all the heavy lifting for generating the Android project.
I added the rest of the instructions in the README, but with Android Studio it's really easy to open the generated Android project from the steps above, and then update Gradle within Android Studio. The build process is 1-click after the Gradle update. I also tested from the command-line using |
The goal of this PR is to build and run an implementation of "Dear ImGui" on Android using SDL bindings/impl and the the OpenGL3 impl.
Here are some important points I've learned since working on this:
imgui/examples/example_android_sdl
there is a setup script included that callswget
to get SDL2 tarball and copies necessary files into the directory (carefully using-rn
not to clobber existing files).../example_android_sdl_gles3/app/jni/src/DearImGuiDemo.cpp
which is pretty much the same as all the other DearImGui examples.imgui_impl_opengl2
file and changing the numbers; I say probably because there's always a gotcha somewhere!SDL_StartTextInput
and updatingAndroidManifest.xml
Android Screenshot