--- a/src/MacSrc/ShockBitmap.c +++ b/src/MacSrc/ShockBitmap.c @@ -27,6 +27,9 @@ #include "Shock.h" #include "ShockBitmap.h" #include "2d.h" +#ifdef __ANDROID__ +#include "OpenGL.h" +#endif //-------------------- // Globals @@ -42,11 +45,26 @@ SDL_RenderClear(renderer); +#ifndef __ANDROID__ + // On Android there's exactly one OS-controlled-size surface - no + // desktop-style window to resize, move, or toggle fullscreen on. + // SDL_SetWindowSize() still "succeeds" there (Android has no + // SetWindowSize driver hook, so SDL's generic layer just overwrites its + // own cached window->w/h to the requested game resolution, e.g. + // 640x480, and synthesizes a resize event from that) - which desyncs + // SDL's own notion of the window size from the real, unchanged Android + // surface size (e.g. 1600x1200), and that desync is exactly what then + // makes both SDL's internal renderer viewport and this engine's own + // custom GL viewport (OpenGL.cc's opengl_resize(), driven by that same + // now-wrong cached size) shrink to the game's resolution instead of + // filling the real surface. Skip the desktop-only calls on Android + // entirely, leaving SDL's window-size bookkeeping untouched. extern bool fullscreenActive; SDL_SetWindowFullscreen(window, fullscreenActive ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); SDL_SetWindowSize(window, width, height); SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); +#endif SDL_RenderSetLogicalSize(renderer, width, height); @@ -54,6 +72,28 @@ gScreenWide = width; gScreenHigh = height; + +#ifdef __ANDROID__ + // Skipping SDL_SetWindowSize() above (see the comment for why) also + // means no native resize event ever fires on Android when the in-game + // resolution changes - opengl_resize() (OpenGL.cc) only ever runs from + // that event (see sdl_events.c) or once at OpenGL init, and it's what + // (re)creates backupBuffer, the offscreen 3D-view render target, sized + // to the logical resolution just changed above. Without this, it stays + // stuck at whatever size it was at launch while the rest of the game + // (drawSurface/gScreenWide/gScreenHigh, just updated above) moves on to + // the new resolution - the actual cause of the display breaking and + // becoming unresponsive to further input after changing resolution + // in-game. Call it directly instead - after gScreenWide/gScreenHigh + // update above, same as the desktop resize event (delivered via + // SDL_PollEvent(), so always processed after this function has already + // returned) - using the same physical window size init_opengl() itself + // used (SDL_GetWindowSize()); that never changes on Android, only the + // logical size set above does. + int physWidth, physHeight; + SDL_GetWindowSize(window, &physWidth, &physHeight); + opengl_resize(physWidth, physHeight); +#endif } //------------------------------------------------------------------------------------