-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Add Android Support #1087
base: master
Are you sure you want to change the base?
Add Android Support #1087
Conversation
very untested may not work at all
untested trying to link it with a native activity results in a linker error
Tested on Xiaomi Redmi Note 4X runnning latest global update
Rendering now works if it is on the main thread
EGL / OpenGL ES also now working
@elmindreda Status on this ? |
…ethods Rotation also works now
@xCuri0 I will be back on Sunday and will start looking through this properly then. |
Please hold off on any further updates in the meantime. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a good foundation for an Android port! Thank you!
This first review is only about necessary minor cleanup and doesn't really address the design.
include/GLFW/glfw3.h
Outdated
@@ -197,7 +197,7 @@ extern "C" { | |||
#include <OpenGL/glu.h> | |||
#endif | |||
|
|||
#else /*__APPLE__*/ | |||
#elif !defined(ANDROID) /*__APPLE__*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't change the default header behavior. I think the application should define one of the GLFW_INCLUDE_ES*
macros if that's what the program uses, just like on desktop.
include/GLFW/glfw3.h
Outdated
@@ -5207,5 +5207,4 @@ GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window | |||
} | |||
#endif | |||
|
|||
#endif /* _glfw3_h_ */ | |||
|
|||
#endif /* _glfw3_h_ */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't remove EOF newline.
include/GLFW/glfw3native.h
Outdated
@@ -564,6 +564,11 @@ GLFWAPI int glfwGetOSMesaDepthBuffer(GLFWwindow* window, int* width, int* height | |||
GLFWAPI OSMesaContext glfwGetOSMesaContext(GLFWwindow* window); | |||
#endif | |||
|
|||
#if defined(GLFW_EXPOSE_NATIVE_ANDROID) | |||
#include <android_native_app_glue.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Platform headers should be included further up in this file.
src/CMakeLists.txt
Outdated
set(glfw_HEADERS ${common_HEADERS} android_platform.h android_joystick.h | ||
posix_time.h posix_thread.h) | ||
set(glfw_SOURCES ${common_SOURCES} android_init.c android_monitor.c android_window.c | ||
android_joystick.c posix_time.c posix_thread.c egl_context.c osmesa_context.c ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Paths that include substitutions should be quoted. Compare with other examples in this file.
src/CMakeLists.txt
Outdated
@@ -95,7 +100,8 @@ target_include_directories(glfw PUBLIC | |||
target_include_directories(glfw PRIVATE | |||
"${GLFW_SOURCE_DIR}/src" | |||
"${GLFW_BINARY_DIR}/src" | |||
${glfw_INCLUDE_DIRS}) | |||
${glfw_INCLUDE_DIRS} | |||
${ANDROID_NDK}/sources/android/native_app_glue/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't hardcode an NDK path for all platforms; instead add it only when building for Android.
src/android_window.c
Outdated
|
||
void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height) | ||
{ | ||
*height = ANativeWindow_getHeight(window->android->window); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either or both of width
and height
may be NULL
.
include/GLFW/glfw3native.h
Outdated
@@ -564,6 +564,11 @@ GLFWAPI int glfwGetOSMesaDepthBuffer(GLFWwindow* window, int* width, int* height | |||
GLFWAPI OSMesaContext glfwGetOSMesaContext(GLFWwindow* window); | |||
#endif | |||
|
|||
#if defined(GLFW_EXPOSE_NATIVE_ANDROID) | |||
#include <android_native_app_glue.h> | |||
GLFWAPI struct android_app * glfwGetAndroidApp(GLFWwindow* window); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There doesn't seem to be a need for a window parameter here as the app struct is available in a global.
src/android_init.c
Outdated
|
||
const char* _glfwPlatformGetVersionString(void) | ||
{ | ||
return _GLFW_VERSION_NUMBER " Android"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version string should list EGL for Android. See the version strings of other platforms.
src/android_window.c
Outdated
|
||
ANativeWindow_setBuffersGeometry(window->android->window, wndconfig->width, wndconfig->height, 0); | ||
|
||
if (ctxconfig->client != GLFW_NO_API) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GLFW uses Allman style.
src/android_window.c
Outdated
|
||
void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos) | ||
{ | ||
*xpos = x; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either or both of xpos
and ypos
may be NULL
.
@elmindreda I've pushed the changes to my fork but for some reason it doesn't show up in the pull request. |
@xCuri0 Must have been a glitch. Looks like it shows up correctly now. |
Thanks, those are good fixes! |
@elmindreda Yep it shows for me now too. Also what do you mean by include substitutions should be quoted ? |
@xCuri0 Thank you! Will try it out asap. |
hi @xCuri0 did you fix the segmentation fault error of the cursor state bug? |
Hey, tried it out on a Nexus 6P, 5X and a Pixel 2 XL. Really want to get this merged. How can I help this PR move forward? @elmindreda |
@kingofoz Not yet. Currently I'm working on finishing version 3.3. @Towerthousand Thanks for asking! You can join forces with @xCuri0 to stabilize and flesh out this port or have a look at #1098 for things to do on the 3.3 release. |
@xCuri0 @elmindreda Took a look at this port and played with improving it a bit. And I think it's impressing and promising. But I have a bunch of questions. I can't find a trivial way to attach (f. ex) multitouch events, mobile sensors to existing API. As GLFW not yet designed as library for mobile platforms, does this port going to extend API or rework (generalize somehow) existing one? And what of compatibility? Or maybe only limited set of mobile features'll be available? I'd like to know what do you think of this problems :) |
@Jeffset As for touch input, have a look at the |
@kingofoz I haven't used a cursor state since it causes segmentation fault. |
@elmindreda Desktop platforms like Windows and Linux also have APIs for sensors.My laptop has an accelerometer used for HDD protection which can be accessed in Linux. |
good job!, I have tested on Galaxy A5 (2016) Android 6.0.1 and it works |
Looks awesome! What's the current status on this? |
it cant run the release version |
@mumin16 Can you tell the Android version of the emulator ? I only tested Nougat MIUI and Oreo 8.1 AOSP. Some people got it working on TouchWiz Marshmallow too |
@mumin16 what is your gui? |
i try it: gui is nuklear |
@mumin16 what's your project? Is it open source project? |
if you press the home, application crashes and we get error : A/libc: Fatal signal 11 (SIGSEGV) at 0x00000017 (code=1). we had been trying to call an uninitialised Canvas inside another Class so when it was trying to get the height or width of it, it would crash. if you rotate mobile device, app locks sometimes. |
@mumin16 both of those are known bugs. I can't implement state saving unless the app using the library stores all its variables in a struct which the library makes |
Excuse me, are there any news ? |
Thanks for your work. |
Is there any movement on this? Would be nice to support all platforms via GLFW... |
It's been almost 6 years. Would love to see the continuation of progress on this PR. |
I think this should actually be revived. Since sdl is the only real alternative supporting android. GLFM for example does not support vulkan so is no real option. |
I added Android support to GLFW. Some features may not be implemented but the basic context creation works.You can test it by importing the
![screenshot_2017-10-03-13-34-16-834_com example native_activity](https://user-images.githubusercontent.com/29529557/31115386-bd26443e-a83f-11e7-87d1-f7d9a4d5b845.png)
![screenshot_2017-09-27-21-24-09-357_com example native_activity](https://user-images.githubusercontent.com/29529557/30923890-c4ba8968-a3ca-11e7-9baf-d1fcf7a2441d.png)
native-activity
sample in Android Studio, adding GLFW toCMakeLists.txt
and changingmain.c
to be like any normal GLFW program.main()
works since the actual entry point is located inandroid_init.c
>android_main()
. OpenGL contexts useegl_context.c
which required little modification to work.Vulkan window surface creation uses the
VK_KHR_android_surface
extension.I tested it on a Xiaomi Redmi Note 4X, please see if it works on other devices if possible.