OK, here’s a test case to demonstrate the problem. With SDL 2.0.3 it resumes from the background correctly, but with SDL 2.0.4 resuming results in a black screen. The simplest way to test is to tap on the Android ‘square’ navigation button to put the app into the background, and then tap the app’s icon to resume. It would be really helpful if somebody can suggest a way forward to resolve this issue.
testcase.c:
Code:
/******************************************************************\
- Testcase to demonstrate problem with SDL 2.0.4 on Android GLES 1 *
******************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <math.h>
#include “SDL.h”
#define GL_COLOR_LOGIC_OP 0x0BF2
#define GL_XOR 0x1506
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 500
#define IDLE 2
#define PACER 20
void (*glEnable) (int) ;
void (*glLogicOp) (int) ;
void (*glDisable) (int) ;
static int bkgnd = 0 ;
int myEventFilter(void* userdata, SDL_Event* pev)
{
switch (pev->type)
{
case SDL_APP_WILLENTERBACKGROUND:
bkgnd = 1 ;
break ;
case SDL_APP_WILLENTERFOREGROUND:
bkgnd = 0 ;
break ;
}
return 0 ;
}
int main(int argc, char* argv[])
{
int running = 1 ;
int sizex, sizey ;
SDL_Event ev ;
SDL_Window *myWindow ;
SDL_Renderer *myRenderer ;
SDL_Rect myRect ;
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER |
SDL_INIT_EVENTS | SDL_INIT_JOYSTICK) != 0)
{
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
“Testcase”, SDL_GetError(), NULL) ;
return 1;
}
#ifdef ANDROID
SDL_SetHint (SDL_HINT_RENDER_DRIVER, “opengles”) ;
SDL_SetHint (SDL_HINT_RENDER_SCALE_QUALITY, “linear”) ;
#else
SDL_SetHint (SDL_HINT_RENDER_DRIVER, “opengl”) ;
SDL_SetHint (SDL_HINT_RENDER_SCALE_QUALITY, “linear”) ;
#endif
myWindow = SDL_CreateWindow(“BBCSDL”, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE) ;
if (myWindow == NULL)
{
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
“Testcase”, SDL_GetError(), NULL) ;
SDL_Quit() ;
return 5;
}
SDL_GetWindowSize (myWindow, &sizex, &sizey) ; // Window may not be the requested size
myRenderer = SDL_CreateRenderer(myWindow, -1, SDL_RENDERER_ACCELERATED |SDL_RENDERER_PRESENTVSYNC) ;
if (myRenderer == NULL)
{
SDL_DestroyWindow(myWindow) ;
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
“Testcase”, SDL_GetError(), NULL) ;
SDL_Quit() ;
return 6;
}
if (!SDL_RenderTargetSupported(myRenderer))
{
SDL_DestroyWindow(myWindow) ;
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
“Testcase”, “Render targets not supported”, NULL) ;
SDL_Quit() ;
return 7;
}
SDL_SetRenderTarget(myRenderer, SDL_CreateTexture(myRenderer, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_TARGET, sizex, sizey)) ;
#ifdef ANDROID
glLogicOp = (void *) dlsym (-1, “glLogicOp”) ;
glEnable = (void *) dlsym (-1, “glEnable”) ;
glDisable = (void *) dlsym (-1, “glDisable”) ;
#else
glLogicOp = SDL_GL_GetProcAddress(“glLogicOp”) ;
glEnable = SDL_GL_GetProcAddress(“glEnable”) ;
glDisable = SDL_GL_GetProcAddress(“glDisable”) ;
#endif
glEnable(GL_COLOR_LOGIC_OP) ;
glLogicOp(GL_XOR) ;
SDL_SetRenderDrawColor(myRenderer, 0, 0, 255, 255) ;
SDL_RenderFillRect(myRenderer, NULL) ;
myRect.x = 0 ;
myRect.y = 0 ;
myRect.w = sizex / 2 ;
myRect.h = sizey ;
SDL_SetRenderDrawColor(myRenderer, 255, 0, 255, 255) ;
SDL_RenderFillRect(myRenderer, &myRect) ;
myRect.x = 0 ;
myRect.y = 0 ;
myRect.w = sizex ;
myRect.h = sizey / 2 ;
SDL_SetRenderDrawColor(myRenderer, 255, 255, 255, 255) ;
SDL_RenderFillRect(myRenderer, &myRect) ;
glDisable(GL_COLOR_LOGIC_OP) ;
SDL_AddEventWatch(myEventFilter, 0) ;
// Main loop:
while (running)
{
static unsigned int zoom = 32768 ;
static int offsetx, offsety ;
unsigned int lastpaint ;
unsigned int now = SDL_GetTicks () ;
float scale = (float)(zoom) / 32768.0 ; // must be float
if (((now >= (lastpaint + PACER)) || (now < lastpaint)) && !bkgnd)
{
int winx, winy ;
SDL_Rect DestRect ;
SDL_Texture *bitmap = SDL_GetRenderTarget (myRenderer) ;
SDL_GetWindowSize (myWindow, &winx, &winy) ;
DestRect.x = -offsetx * scale ;
DestRect.y = -offsety * scale ;
DestRect.w = sizex * scale ;
DestRect.h = sizey * scale ;
DestRect.x += (winx - DestRect.w) >> 1 ;
SDL_SetRenderTarget(myRenderer, NULL) ;
SDL_SetRenderDrawColor (myRenderer, 0, 0, 0, 255) ;
SDL_RenderClear (myRenderer) ;
SDL_RenderCopy(myRenderer, bitmap, NULL, &DestRect) ;
SDL_RenderPresent(myRenderer) ;
SDL_SetRenderTarget(myRenderer, bitmap) ;
lastpaint = SDL_GetTicks() ; // wraps around after 50 days
}
SDL_PumpEvents () ;
if (SDL_PeepEvents(&ev, 1, SDL_GETEVENT, 0, SDL_USEREVENT-1))
switch (ev.type)
{
static float panx, pany ;
case SDL_QUIT:
running = 0 ;
break ;
case SDL_MULTIGESTURE :
if (fabs(ev.mgesture.dDist) > 0.002)
zoom = zoom * (1.0 + ev.mgesture.dDist) /
(1.0 - ev.mgesture.dDist) ;
if (fabs(ev.mgesture.x - panx) < 0.05)
offsetx -= sizex * (ev.mgesture.x - panx) / scale ;
if (fabs(ev.mgesture.y - pany) < 0.05)
offsety -= sizey * (ev.mgesture.y - pany) / scale ;
panx = ev.mgesture.x ;
pany = ev.mgesture.y ;
break ;
}
else
SDL_Delay (IDLE) ;
}
SDL_DestroyRenderer(myRenderer) ;
SDL_DestroyWindow(myWindow) ;
SDL_Quit() ;
exit(0) ;
}
AndroidManifest.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<!-- Create a Java class extending SDLActivity and place it in a
directory under src matching the package, e.g.
src/com/gamemaker/game/MyGame.java
then replace "SDLActivity" with the name of your class (e.g. "MyGame")
in the XML below.
An example Java class can be found in README-android.txt
-->
<application android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:allowBackup="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:hardwareAccelerated="true" >
<activity android:name="TestCase"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<!-- Android 2.3.3 -->
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="15" />
<!-- OpenGL ES 2.0 -->
<!-- uses-feature android:glEsVersion="0x00020000" -->
<!-- Allow writing to external storage -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Richard.