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

Android + OpenGL ES 3 Example #421

Open
wants to merge 68 commits into
base: master
from

Conversation

Projects
None yet
7 participants
@zmertens
Copy link

commented Dec 1, 2015

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:

  • SDL already has an Android bootstrap project in it's repository
  • In imgui/examples/example_android_sdl there is a setup script included that calls wget to get SDL2 tarball and copies necessary files into the directory (carefully using -rn not to clobber existing files)
  • The existing files within the directory contain mostly Android makefiles, manifests, and Gradle build scripts which are necessary for distinguishing the "Dear ImGui" package and configurations.
  • The most relevant file is the .../example_android_sdl_gles3/app/jni/src/DearImGuiDemo.cpp which is pretty much the same as all the other DearImGui examples.
  • You can probably drop down to OpenGLES2 by just grabbing the imgui_impl_opengl2 file and changing the numbers; I say probably because there's always a gotcha somewhere!
  • This example does not contain keyboard or voice input or any of that fancy stuff, but I can attest to using keyboard input by adding SDL_StartTextInput and updating AndroidManifest.xml
  • I would love to hear some ideas on easily fitting the gui to a mobile device (emphasis on easy!)

Android Screenshot

zryan3
added android example and modified gitignore to avoid unnecessary And…
…roid related files

modified android_example to remove SDL2 files, clean up the imgui_impl_sdl_gles2 to be more readable, modify the README for build instructions for android_example, and modify the .gitignore for unnecessary Android Studio and Gradle files

refactored the android_example
@ocornut

This comment has been minimized.

Copy link
Owner

commented Dec 2, 2015

Thanks! Will look at it when I have time.

@sabotage3d

This comment has been minimized.

Copy link

commented Aug 11, 2016

Hi guys I cannot find the android example in the repository. Can someone share it please?

@ocornut

This comment has been minimized.

Copy link
Owner

commented Aug 11, 2016

Search for "Android" on github I believe there is (unsupported) example for it.

On 11 Aug 2016, at 15:15, sabotage3d notifications@github.com wrote:

Hi guys I cannot find the android example in the repository. Can someone share it please?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

@zmertens

This comment has been minimized.

Copy link
Author

commented Aug 11, 2016

@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).

@kingofoz

This comment has been minimized.

Copy link

commented Nov 28, 2017

hello,
Is Android supported by imgui?

@ocornut

This comment has been minimized.

Copy link
Owner

commented Nov 28, 2017

@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.

@elect86

This comment has been minimized.

Copy link
Contributor

commented Nov 28, 2017

If interested, I'm working on a jvm port

@ocornut ocornut force-pushed the ocornut:master branch to a265837 Feb 12, 2018

@ice1000

This comment has been minimized.

Copy link
Contributor

commented Jul 17, 2018

What's the current status of this pr?

@ocornut ocornut changed the title Android Example Android + OpenGL ES 2 Example Jul 17, 2018

@ocornut ocornut added the opengl label Jul 17, 2018

@ocornut

This comment has been minimized.

Copy link
Owner

commented Jul 17, 2018

@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.
image

@ocornut

This comment has been minimized.

Copy link
Owner

commented Nov 9, 2018

People coming to this link in 2018:
Note with the current examples/ infrastructure you should be able to use imgui_impl_opengl3.cpp directly. Minor patches may be welcome to support GL ES 2.

An actual Android example will minimum cruft/bloat would be nice.

@zmertens

This comment has been minimized.

Copy link
Author

commented Nov 10, 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.

ocornut added a commit that referenced this pull request Dec 21, 2018

zmertens added some commits Dec 21, 2018

Fix merge conflict \
imgui_impl_sdl.cpp
@zmertens

This comment has been minimized.

Copy link
Author

commented Dec 29, 2018

Should .travis.yml be updated as well to build this example for Android? I made a small game using imgui and this is what I did for my travis file.

zmertens added some commits Jan 6, 2019

Update examples/README for better information \
Update setup_android script to use variables more efficiently \
Update gitignore to preciscely ignore SDL dir
Update DearImguiActivity.java
Add newline to the end of file
Update setup_android.sh
Add newline to the end of file
Update DearImGuiDemo.cpp
Update code to clearly state that `ImGuiConfigFlags_NoMouseCursorChange` prevents an error

@ocornut ocornut force-pushed the ocornut:master branch from 008954d to 16c0a02 Jan 31, 2019

@ocornut ocornut force-pushed the ocornut:master branch from 2d5eb47 to 6db0766 Apr 24, 2019

@zmertens

This comment has been minimized.

Copy link
Author

commented Apr 30, 2019

I've thought about this PR quite a bit and I think I have come to three main conclusions:

  • I'm not sure if I can minimize the files too much more without relying on an Android project template from an external site that would need to get pulled down using curl or wget from a Makefile or shell script. That's kind of what the setup_android.sh script does right now for SDL2-android.

  • I don't think there's much else I can do with the example without deviating from the other imgui examples and creating a whole new specific interface (it would become a lot less generic and more tailored to a specific use case).

  • Anyone looking to test it should use a real device. Android emulators and C++ projects are tricky to get to work, and I have not gotten it to work thus far.

I'm still open to ideas so it could be something useful for the master branch someday or it can just remain here.

@sariug

This comment has been minimized.

Copy link

commented May 2, 2019

sorry for interruption, a noob question here.
So I just downloaded this branch as well as studio. I also have an outer tablet to try the things with. Would that be ok to directly make this program work or should I do something extra ?

sorry for inconvenience.

edit: the answer is yes. It worked nicely. The problem is for text input the keyboard does not appear. Does any of you know how to make it ?

@zmertens

This comment has been minimized.

Copy link
Author

commented May 2, 2019

edit: the answer is yes. It worked nicely. The problem is for text input the keyboard does not appear. Does any of you know how to make it ?

Yes, in examples/example_android_sdl_gles3/app/jni/src/DearImGuiDemo.cpp, add this SDL_StartTextInput, like so:

    SDL_StartTextInput() // add this code around line 105
    // Main loop
    bool done = false;
    while (!done)
    {
        ...
        // imgui new frame and render functions
    }
    ... // destroy context and friends
    // exit

A virtual keyboard should pop up on your device. I had some issues with my spacebar working on my phone though!

@ocornut ocornut force-pushed the ocornut:master branch from 1b84280 to aca6ee1 May 11, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.