Skip to content

Commit

Permalink
[Android] Added global variable "g_androidApp" to ExampleBase_C99 pro…
Browse files Browse the repository at this point in the history
…ject.

This allows to access the global 'struct android_app*' variable from the android_main() entry point in all C99 examples.
  • Loading branch information
LukasBanana committed Sep 2, 2024
1 parent 5ae125c commit b72c251
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 8 additions & 4 deletions examples/C99/ExampleBase/ExampleBase.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ ExampleConfig g_config = { .rendererDesc.moduleName = "OpenG
.debugger = false,
.noDepthStencil = false };

#if defined(ANDROID) || defined(__ANDROID__)
struct android_app* g_androidApp = NULL;
#endif


/*
* Internals
Expand Down Expand Up @@ -138,14 +142,14 @@ static float aspect_ratio()
static void example_config(const ExampleArgs* args)
{
#if defined(ANDROID) || defined(__ANDROID__)
struct android_app* androidApp = args->androidApp;
g_androidApp = args->androidApp;

g_config.rendererDesc.moduleName = "OpenGLES3";
g_config.rendererDesc.androidApp = androidApp;
g_config.rendererDesc.androidApp = g_androidApp;

// Store pointer to asset manager so we can load assets from the APK bundle
if (androidApp->activity != NULL)
AndroidSetAssetManager(androidApp->activity->assetManager);
if (g_androidApp->activity != NULL)
AndroidSetAssetManager(g_androidApp->activity->assetManager);
#else
g_config.rendererDesc.moduleName = "OpenGL";
g_config.resolution[0] = 800;
Expand Down
5 changes: 5 additions & 0 deletions examples/C99/ExampleBase/ExampleBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ extern float g_projection[4][4];
// Render system configuraiton.
extern ExampleConfig g_config;

// Android app glue structure. Only available on Android platform.
#if defined(ANDROID) || defined(__ANDROID__)
extern struct android_app* g_androidApp;
#endif


/*
* Global functions
Expand Down

0 comments on commit b72c251

Please sign in to comment.