I see your frustration, but this is intentional. What about people running multiple apps that use OpenGL? There's one device, so one instance makes sense.
By using onPause(), onClose(), onStart(), and onResume(), you should be able to handle these issues.
And if you really want to (and it seems you do), you can call finish() to exit your app at any time you like. Yup, it'll do it.
Oh yeah, these are all methods you call from your Activity.
im new to android and im just learning java, i wanted to know how to make 3d games for android, is opengl a different program or does it come in eclipse thanks
I'm note sure, but i think this is done with: protected void onPause(){ super.onPause(); mGLView.onPause(); } protected void onResume(){ super.onResume(); mGLView.onResume(); }
}
I think the View.onPause should keep the state of the GL scene, But i'm just starting to mess with And-OGL. Let me know if i'm wrong... got this from: developer.android.com/resources/tutorials/opengl/opengl-es10.html
I'm not an android dev, but isn't there an event fired when the home button is pressed (onThombstone or something?) that way you can really quit your app (possibly save game state) so that you dont have to worry about this?
Nice video! I've coded some Android stuff and some OpenGL, but not a single line of OpenGL on Android. However, this is how I assumed it'd work. Isn't it is obvious that you can't rely on the context being present when you switch back considering that the Activity might get automagically get deleted if there's only tiny amount of memory left on the system etc?
Since this method is called at the beginning of rendering, as well as every time the EGL context is lost, this method is a convenient place to put code to create resources that need to be created when the rendering starts, and that need to be recreated when the EGL context is lost..."
I was more worried that GL resources would get out of hand. I think this is fairly reasonable.
@xinaesthetic I used onSurfaceCreated as the entry point for restoring all the OpenGL assets. So yeah, it was not a terribly difficult fix. It's just frustrating that the assets die in the first place.
@cyborusDev in a way it's frustrating.... but there could be a lot of garbage otherwise. Anyway, it wasn't too badly hidden in the documentation. At least, it so happened that *particular* thing didn't catch me out; I had some obscurity with glCopyTexSubImage2d not working but that's a different story.
This reminds me of what happens with XNA/Windows Phone. You've got to recreate all your device objects when this happens, but at least with XNA, they're pretty explicit about it.
If you're using Java, you can simply use GLSurfaceView + GLSurfaceView.Renderer to capture the events (+it shifts rendering out into a seperate thread).
Yeah lost resources or even a lost device is a common problem on Windows with DirectX aswell. Even OpenGL could need some restoring after a window switch. Linux on the other side handles OpenGL contexts much better, never ever had a lost resource with it. Best way to handle this in my opinion is some sort of restore chain through the engine which is called when a device was lost. It checks if resources need to be reloaded and so on.
That sucks!! I've never used OpenGL (plan too at some stage, I think i tried it a while back for like 10 minutes, but that was it) by the sounds of things you could potentially end up with having to reload a LOT of assets on program "entry" now i know why there is a short pause with some of my android applications such as gameboid when i open it up again from its "sleep state"
Those are some big rings below your eyes man!
veeableful 1 month ago
Great, thanks for sharing this, quite interesting to know :)
TuxedoPanther 1 month ago
I see your frustration, but this is intentional. What about people running multiple apps that use OpenGL? There's one device, so one instance makes sense.
By using onPause(), onClose(), onStart(), and onResume(), you should be able to handle these issues.
And if you really want to (and it seems you do), you can call finish() to exit your app at any time you like. Yup, it'll do it.
Oh yeah, these are all methods you call from your Activity.
-scott biggs
smb10011001 4 months ago
there's no way to preserve data? instances? bundle data? never heard of that?
xasdrubalex 4 months ago
im new to android and im just learning java, i wanted to know how to make 3d games for android, is opengl a different program or does it come in eclipse thanks
jarocho151 5 months ago
I'm note sure, but i think this is done with: protected void onPause(){ super.onPause(); mGLView.onPause(); } protected void onResume(){ super.onResume(); mGLView.onResume(); }
}
I think the View.onPause should keep the state of the GL scene, But i'm just starting to mess with And-OGL. Let me know if i'm wrong... got this from: developer.android.com/resources/tutorials/opengl/opengl-es10.html
UCdevnull 6 months ago
This has been flagged as spam show
so whats the deal?
redhotbits 9 months ago
I'm not an android dev, but isn't there an event fired when the home button is pressed (onThombstone or something?) that way you can really quit your app (possibly save game state) so that you dont have to worry about this?
RoyTriesscheijn 11 months ago
Nice video! I've coded some Android stuff and some OpenGL, but not a single line of OpenGL on Android. However, this is how I assumed it'd work. Isn't it is obvious that you can't rely on the context being present when you switch back considering that the Activity might get automagically get deleted if there's only tiny amount of memory left on the system etc?
arttuy 11 months ago
Awesome!
fullbleed T-Shirt?
RungAaz 1 year ago
Reminds me of onResetDevice() in DirectX on Windows. Interesting.
Have to rebuild/reload everything that isn't managed by DirectX when ALT-Tab is pressed in a full-screen app.
interneteffects 1 year ago
onLoad() man... thats all we need! :)
hebronsawyers 1 year ago
"Renderer.onSurfaceCreated (GL10 gl, EGLConfig config)
Called when the surface is created or recreated.
...
Since this method is called at the beginning of rendering, as well as every time the EGL context is lost, this method is a convenient place to put code to create resources that need to be created when the rendering starts, and that need to be recreated when the EGL context is lost..."
I was more worried that GL resources would get out of hand. I think this is fairly reasonable.
xinaesthetic 1 year ago
@xinaesthetic I used onSurfaceCreated as the entry point for restoring all the OpenGL assets. So yeah, it was not a terribly difficult fix. It's just frustrating that the assets die in the first place.
cyborusDev 1 year ago
@cyborusDev in a way it's frustrating.... but there could be a lot of garbage otherwise. Anyway, it wasn't too badly hidden in the documentation. At least, it so happened that *particular* thing didn't catch me out; I had some obscurity with glCopyTexSubImage2d not working but that's a different story.
xinaesthetic 1 year ago
Have you check to see if its the cell phone?
plutoamun 1 year ago
@plutoamun What? Like as if my phone is defective or something?
cyborusDev 1 year ago
That really blows, oh well I see why it would be that way
eatcomics 1 year ago
This reminds me of what happens with XNA/Windows Phone. You've got to recreate all your device objects when this happens, but at least with XNA, they're pretty explicit about it.
vargonian 1 year ago
Are you using the NDK or Java?
If you're using Java, you can simply use GLSurfaceView + GLSurfaceView.Renderer to capture the events (+it shifts rendering out into a seperate thread).
MilchTheShake 1 year ago
@MilchTheShake I'm using both. I have a GLSurfaceView piping rendering events off to NDK code.
cyborusDev 1 year ago
Yeah lost resources or even a lost device is a common problem on Windows with DirectX aswell. Even OpenGL could need some restoring after a window switch. Linux on the other side handles OpenGL contexts much better, never ever had a lost resource with it. Best way to handle this in my opinion is some sort of restore chain through the engine which is called when a device was lost. It checks if resources need to be reloaded and so on.
NemexNexSoft 1 year ago
That sucks!! I've never used OpenGL (plan too at some stage, I think i tried it a while back for like 10 minutes, but that was it) by the sounds of things you could potentially end up with having to reload a LOT of assets on program "entry" now i know why there is a short pause with some of my android applications such as gameboid when i open it up again from its "sleep state"
CodeCriminal 1 year ago