How to get 32-bit screen on Android

I’m migrating my app from NativeActivity to SDL. When I used NativeActivity, ANativeWindow_getFormat() returned RGBX_8888 which was just fine. With SDL’s renderer, however, the surfaceChanged() callback in the Java glue code always receives RGB_565 as the pixel format which looks rather ugly because it only has 65536 colors and gradients look pretty cheap in 16 bits.

So I tried to add the following code to SDLActivity’s onCreate() before calling setContentView():

getWindow().setFormat(PixelFormat.RGBX_8888);

This indeed solves the problem on my Nexus 5X device running Android 8 but on my Nexus 9 tablet running Android 7 it doesn’t work and I still get 16-bit surfaces.

What is confusing me, however, is the fact that when using NativeActivity on my Nexus 9 tablet running Android 7 I actually get RGBX_8888 surfaces! So this definitely is not a hardware/system limitation on Nexus 9/Android 7. It works for NativeActivity, but not for SDL although both, SDLActivity and NativeActivity seem to be based on SurfaceView. This is rather confusing me.

So does anybody have an idea of how I could get 32-bit graphics with SDL like I can get with NativeActivity?

I haven’t checked if this actually works currently on Android, but have you tried using the appropriate attributes in SDL:

SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);

And if you really need the alpha channel (not needed usually even when drawing transparent stuff)

SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);

I would think those should also work on Android. If they don’t you should file a bug.

Note that the attributes must be set before creating the GL context.

Oh great, this indeed does the trick! Thanks a lot for the hint!