Repository navigation
harmonyos: Port SDL3 to HarmonyOS/OpenHarmony. - #16281
Conversation
|
This has been sitting on a branch forever, so it's time to get it into a PR. There are some pieces that are still unimplemented, but this is more than enough to ship serious games and apps. The largest missing piece is joystick support; there is a GameControllerKit API that can be used, but this has not been attempted yet. The rest of the missing pieces are minor (pen support, dialogs, etc, see the "STILL TODO" section of the readme). This is definitely quite competitive with the Android and iOS ports at this point, though. This branch is squashed/rebased against main. All 77 commits of the work are sitting in my sdl3-harmonyos branch, but this isn't interesting except for historical purposes. I need to verify this still works after rebasing, which I'll do tonight. We'll leave this as draft until then. |
|
testsybols.c needs touching, like below I guess? diff --git a/test/testsymbols.c b/test/testsymbols.c
index 3b5591e..2eb4f24 100644
--- a/test/testsymbols.c
+++ b/test/testsymbols.c
@@ -34,6 +34,12 @@ extern SDL_DECLSPEC void SDLCALL SDL_SendAndroidMessage(void);
extern SDL_DECLSPEC void SDLCALL SDL_ShowAndroidToast(void);
#endif
+#ifndef SDL_PLATFORM_OPENHARMONY
+extern SDL_DECLSPEC int SDLCALL SDL_GetOpenHarmonySDKVersion(void);
+extern SDL_DECLSPEC void SDLCALL SDL_GetOpenHarmonyInternalStoragePath(void);
+extern SDL_DECLSPEC bool SDLCALL SDL_RequestOpenHarmonyPermission(void);
+#endif
+
#if !defined(SDL_PLATFORM_GDK)
extern SDL_DECLSPEC void SDLCALL SDL_GDKResumeGPU(void);
extern SDL_DECLSPEC void SDLCALL SDL_GDKSuspendGPU(void); |
So does it work on emulators? |
f4274cc to
8be8613
Compare
I don't know; DevEco Studio doesn't offer emulators outside of mainland China, except for smartwatches, apparently. If it still doesn't work for you on an emulator, let's try to figure out why. |
Fixed this up and a handful of other mistakes. |
Seems like 2in1 device supports are missing |
Simple gl test works, but it crashes with js error(input method client detached, need to be attached first), seems like initialization issues |
And I hope the single app entrypoint's name is "main", not "SDL_main" (or try to load either funcs) |
We attach it when showing the keyboard...if there's a project somewhere I can look at, I'll try to reproduce the issue here.
What needs to be done for this?
It loads "SDL_main", and expects the source file with a "main" function to include SDL_main.h, like all other platforms. |
for the first question, the sample app in my port can reproduce it, for the second question, you can add "2in1" to the list containing "phone" (you can search it, it is inside a json file) |
This is fixed in 16cc084, thanks! I'll try your sample app later today and see what problems I run into. |
Okay, I needed to make some changes, but I got it working: trim.2996FBB3-5B4C-4A6C-8EBA-098E6988F6F4.MOV
The specific changes I made: --- ../SDL-OpenMinecraft/ohos-project/entry/src/main/cpp/entrypoint.cpp 2026-09-10 17:50:00.098754462 -0400
+++ openharmony-project/entry/src/main/cpp/entrypoint.cpp 2026-09-10 22:34:52.877388785 -0400
@@ -13,6 +13,7 @@
#include "SDL3/SDL_power.h"
#include "SDL3/SDL_dialog.h"
#include "SDL3/SDL_sensor.h"
+#include "SDL3/SDL_main.h"
#include <GLES2/gl2.h>
#include <stdlib.h>
#include <thread>
@@ -34,7 +35,7 @@
1.f, 0.f, 0.f
};
-int main()
+int main(int argc, char **argv)
{
/*OH_AudioStreamBuilder* builder;
OH_AudioStreamBuilder_Create(&builder, AUDIOSTREAM_TYPE_RENDERER);
@@ -70,9 +71,9 @@
OH_AudioRenderer_Start(audioRenderer);
OH_AudioStreamBuilder_Destroy(builder);*/
- SDL_SetHint(SDL_HINT_EGL_LIBRARY, "libEGL.so");
- SDL_SetHint(SDL_HINT_OPENGL_LIBRARY, "libGLESv2.so");
- SDL_SetHint(SDL_HINT_OPENGL_ES_DRIVER, "libGLESv2.so");
+ //SDL_SetHint(SDL_HINT_EGL_LIBRARY, "libEGL.so");
+ //SDL_SetHint(SDL_HINT_OPENGL_LIBRARY, "libGLESv2.so");
+ //SDL_SetHint(SDL_HINT_OPENGL_ES_DRIVER, "libGLESv2.so");
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
@@ -92,7 +93,7 @@
int frgshader = ((PFNGLCREATESHADERPROC)SDL_GL_GetProcAddress("glCreateShader"))(GL_FRAGMENT_SHADER);
int vexshader = ((PFNGLCREATESHADERPROC)SDL_GL_GetProcAddress("glCreateShader"))(GL_VERTEX_SHADER);
- auto frag = "varying vec4 v_color;void main() {gl_FragColor = v_color;}";
+ auto frag = "precision lowp float; varying vec4 v_color;void main() {gl_FragColor = v_color;}";
((PFNGLSHADERSOURCEPROC)SDL_GL_GetProcAddress("glShaderSource"))(frgshader, 1, &frag, nullptr);
((PFNGLCOMPILESHADERPROC)SDL_GL_GetProcAddress("glCompileShader"))(frgshader);
int status = 1; |
ime crash still happens sometimes |
|
If there's a crash you can reproduce, it would be helpful if you could either catch it in the debugger, or find the stacktrace or any reasonable error messages in hilog and post it here. |
16cc084 to
ee7470d
Compare
This is my port of SDL3 to HarmonyOS/OpenHarmony. It has been tested on real hardware from Huawei, and commercial games are being prepped to ship with it already. There is _heavy_ documentation in docs/README-harmonyos.md, including how to set up a development environment and project, build, and debug, for the completely uninitiated. This work was sponsored by Outfit7: https://outfit7.com/ Fixes libsdl-org#9837.
ee7470d to
158d10f
Compare
|
Going to merge this tonight; other bugs that might show up can be fixed after. |
This is my port of SDL3 to HarmonyOS/OpenHarmony. It has been tested on real hardware from Huawei, and commercial games are being prepped to ship with it already.
There is heavy documentation in docs/README-harmonyos.md, including how to set up a development environment and project, build, and debug, for the completely uninitiated.
This work was sponsored by Outfit7: https://outfit7.com/
Fixes #9837.