This is intended to be a minimal working example of desktop + android cross platform graphic app using glutin
and gl
Simple opengl example taken from tomka/glutin's window example to draw on both desktop and mobile.
Modified to check for mouse & touch input. Click / press inside the window to change the background color!
This example uses of tomaka/cargo-apk's docker image to build the apk. You can do it without docker, but it is more intensive and not as portable of a setup. I haven't testing it without the docker, but I assume it would work as its the same stuff going on inside and outside the docker image. I would recommend the docker image though, might be a hastle to setup but it does help in the future with building for specific environments.
I use docker-compose instead of a Dockerfile or command because it makes it easier to declare specific tasks for the docker image.
I also use just for all the commands to run. You don't need this as the justfile
is fairly easy to see whats actually going on, but for convinence I recommend checking it out in your own projects.
First you need to build for android, everything is setup in the docker image so nothing additional is required. If you will use libraries that need to compile for android, you will need to do that in a custom docker image (or you can have then prebuilt as *.so files), and list their location in a .cargo/config
file in the project directory. In the case of the example there are no libraries.
To build for android using the just runner
just build-android
Or if you just want to use docker, with docker-compose,
docker-compose run android
Or plain docker if you don't want to use docker-compose,
docker run --rm -v .:/root/src tomaka/cargo-apk cargo apk build
Sometimes the above command doesn't work in windows because of a docker pathing issue. If this gives you an error about path being too short, then just change .
to the absolute path to the directory: C:\Users\parent\directory\of\toml
.
Then you can install to android using ADB
The command is already listed in just, which will uninstall the previous version and install the newer version.
just install-android
Not all links here are part of this working example, but they all got me here. I wanted to keep them because I found them useful on the journey and might need to reference them again as I go further down this rabbithole.
OpenGL
- https://docs.rs/gl_generator/0.9.0/gl_generator/
- http://nercury.github.io/rust/opengl/tutorial/2018/02/08/opengl-in-rust-from-scratch-01-window.html
SDL2
- https://rust-sdl2.github.io/rust-sdl2/sdl2/
- https://rust-sdl2.github.io/rust-sdl2/sdl2/video/index.html
Rust & Graphics on Mobile
- https://michaelfairley.com/blog/i-made-a-game-in-rust/
- https://www.reddit.com/r/rust/comments/9bq7df/iphone8_screenshot_of_gfxhal_with_a_metal_backend/
Building Rust for Android