Can't restore screen when lost screen

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

Can't restore screen when lost screen

Postby aaronzheng » Wed Jan 13, 2010 12:21 pm

I develope my 2d game with opengl es , when the handset lock the sceen, I pressed keys to go back to the game, but I can only see a white blank screen, all of my drawing objects are disappeared.
It seems that the textures and VBOs are ineffective.
I use my G1 to develope my games.
Who can help me?
aaronzheng
Freshman
Freshman
 
Posts: 7
Joined: Wed Jan 13, 2010 12:07 pm

Top

Postby zorro » Wed Jan 13, 2010 1:55 pm

When something is pausing your game, you have to load all the textures and recreate all the VBOs after the resuming. The rest of the data (non OpenGL related) are not lost.
User avatar
zorro
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Mon Aug 10, 2009 3:11 pm
Location: Romania

Postby aaronzheng » Thu Jan 14, 2010 2:57 am

[quote="zorro"]When something is pausing your game, you have to load all the textures and recreate all the VBOs after the resuming. The rest of the data (non OpenGL related) are not lost.[/quote]

Thanks for your replies.
Should I release all the textures and VBOs after pausing my game and recreate the gl object?

Strangely, I tested my game with a little PNGs and VBOs yesterday, the screen restored automatically.
aaronzheng
Freshman
Freshman
 
Posts: 7
Joined: Wed Jan 13, 2010 12:07 pm

Postby zorro » Thu Jan 14, 2010 8:46 am

I think it worked because the phone didn't release your old resources, but this is not going to work all the times. I found on a forum some advices about pause/resuming in opengl on android and I found them useful. Here they are:

- Your activity should only be creating one GLSurfaceView in onCreate and releasing it in onDestroy
- Your activity onPause and onResume must call your GLSurfaceView's onPause and onResume.
- Ideally, your GLSurfaceView will create your renderer.
- Your renderer needs to reload everything (textures, vbos, etc) to video memory when the surface has hanged.
- After the surface has changed, when reloading, get all new texture and vertex buffer IDs. Do not use the old ones or you could crash the gl system.

So you must reload (load, when app starts first time) everything in onSurfaceCreated. If the system calls that it means that the surface was recreated and all GL data must be reloaded. You don't need to free the old textures yourself, they were lost when the surface was destroyed.
User avatar
zorro
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Mon Aug 10, 2009 3:11 pm
Location: Romania

Postby aaronzheng » Thu Jan 14, 2010 10:35 am

[quote="zorro"]I think it worked because the phone didn't release your old resources, but this is not going to work all the times. I found on a forum some advices about pause/resuming in opengl on android and I found them useful. Here they are:

- Your activity should only be creating one GLSurfaceView in onCreate and releasing it in onDestroy
- Your activity onPause and onResume must call your GLSurfaceView's onPause and onResume.
- Ideally, your GLSurfaceView will create your renderer.
- Your renderer needs to reload everything (textures, vbos, etc) to video memory when the surface has hanged.
- After the surface has changed, when reloading, get all new texture and vertex buffer IDs. Do not use the old ones or you could crash the gl system.

So you must reload (load, when app starts first time) everything in onSurfaceCreated. If the system calls that it means that the surface was recreated and all GL data must be reloaded. You don't need to free the old textures yourself, they were lost when the surface was destroyed.[/quote]


Great Thanks for your advices.

I reload everything (textures, vbos, etc) to video memory when the surface has changed, it woks fine
when i press the "home" key to go out the game and switch back to the game by running-programming panel(by long pressing "home" key on my G1).
However, When i press the "nocall" key, the screen locked and turn black. then i press the "call" key to light the
screen, the handset hint me to press "menu" key to unlock, i unlock the screen, the result is the same as before, a few objects are drawing on the screen, lots of them are disappeared.
I am sure i reload everything after I press "call" key. :cry:
aaronzheng
Freshman
Freshman
 
Posts: 7
Joined: Wed Jan 13, 2010 12:07 pm

Postby zorro » Thu Jan 14, 2010 11:26 am

I tried your scenario (press NoCall then Unlock Screen and resuming the app) and all worked fine. The framework called OnResume. However I didn't log if the onSurfaceCreated was called again. My mechanism of handling the pause/resume is done this way: at OnPause i save (using SharedPreferences class) the game state, then at OnResume i check the saved state and load everything from scratch to obtain that state (menu, game, etc). So I don't load the resources in onSurfaceCreated. I don't know if it's the right way, but it's logical and works fine.
User avatar
zorro
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Mon Aug 10, 2009 3:11 pm
Location: Romania

Top

Postby aaronzheng » Thu Jan 14, 2010 12:55 pm

I think I should reload everything when the game get focus, because the framework calls my game's onResume() first , then the lock-screen covers my game and my GL objects(textures , VOBs , etc) are not effective any more.
aaronzheng
Freshman
Freshman
 
Posts: 7
Joined: Wed Jan 13, 2010 12:07 pm

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests