Are there any minimal samples for using Godot with Android GLSurfaceview

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By finleyPan

Recently I tried to integrate Godot into our system on Android. Basically we use GLSurfaceview with a custom renderer which implements onDrawFrame callback to finish concrete rendering jobs.
I initialize Godot Engine in the onSurfaceCreated callback:

JNIEXPORT void JNICALL
Java_com_example_godottest_GodotRenderer_setup(JNIEnv *env, jclass clazz, jstring project_dir) {
    auto tmp = env->GetStringUTFChars(project_dir, nullptr);
    char argv0[] = "--path";
    char argv1[512];
    strcpy(argv1, tmp);
    env->ReleaseStringUTFChars(project_dir, tmp);
    char* argvs[] = {argv0, argv1};
    os = new OS_Zeus;
    CHECK(Main::setup("godot", 2, argvs, true));

    if(Main::start()){
        auto main_loop = os->get_main_loop();
        main_loop->init();
        auto st = Object::cast_to<SceneTree>(main_loop);
        st->set_viewport_size(Size2(1280, 720));
        VisualServer *vs = VisualServer::get_singleton();
//        vs->viewport_set_update_mode(st->get_root_rid(), VS::VIEWPORT_UPDATE_ALWAYS);
    }else{
        LOGE("init not finished!");
    }
}

And do rendering as follows:

public void onDrawFrame(GL10 gl10) {
...
GodotRenderer.doRender(delta);
...
}

JNIEXPORT void JNICALL
Java_com_example_godottest_GodotRenderer_doRender(JNIEnv *env, jclass clazz, jfloat delta) {
    Main::iteration();
}

My application appears blank screen when running, I hooked logs from Godot during setup:

01-29 14:26:56.238 29962 30078 I ZeusGodotEngine: Main: Initialize CORE
01-29 14:26:56.262 29962 30078 I ZeusGodotEngine: Main: Initialize Globals
01-29 14:26:56.272 29962 30078 I ZeusGodotEngine: Main: Parse CMDLine
01-29 14:26:56.277 29962 30078 I ZeusGodotEngine: Godot Engine v3.5.1.stable.custom_build.8f5557f2d - https://godotengine.org
01-29 14:26:56.287 29962 30078 I ZeusGodotEngine: OpenGL ES 3.0 Renderer: Adreno (TM) 650
01-29 14:26:56.287 29962 30078 I ZeusGodotEngine: Async. shader compilation: OFF
01-29 14:26:56.373 29962 30078 I ZeusGodotEngine:
01-29 14:26:56.375 29962 30078 I ZeusGodotEngine: Main: Setup Logo
01-29 14:26:56.384 29962 30078 I ZeusGodotEngine: Main: Load Boot Image
01-29 14:26:56.384 29962 30078 I ZeusGodotEngine: Main: DCC
01-29 14:26:56.384 29962 30078 I ZeusGodotEngine: Main: Load Translations and Remaps
01-29 14:26:56.384 29962 30078 I ZeusGodotEngine: Main: Load Scene Types
01-29 14:26:56.469 29962 30078 I ZeusGodotEngine: Main: Load Modules, Physics, Drivers, Scripts
01-29 14:26:56.579 29962 30078 I ZeusGodotEngine: Main: Done

It seems setup and initialization succeed. So are there any other jobs to do for working it out or can anyone provide minimum samples? :slight_smile:

Ok so used to be an avid Android developer here
Was on the crew to port blender to Android then Ton dropped the game engine and that’s how i started using Godot.

Have been poking around the Godot source and have to say you probably won’t find someone as “hooked” in as me JNI + Java + opensource (C++).

Yet have to wonder why you would want to do this when Godot already has an Android export that you can modify using a custom export.

Honestly it seems redundant and before walking down that road with you gotta know why

Wakatta | 2023-01-29 23:53

Ok, put it simply, my team adopt godot for making video effects rather than games, because godot editor is out-of-the-box. So what we need is only the “rendering” function of godot: render a scene into an external texture. So a deep customization is necessary

finleyPan | 2023-01-30 04:24

Apologies for the late reply.

Blank screen can be that you’ve not swapped buffers

Will do a deeper dive and try to compile.

Also to answer your question this is way beyond the general scope of the Godot Docs so most likely you will not find examples and would have to ask a dev directly in the irc channel

Wakatta | 2023-02-10 00:03