I read somewhere that OpenGL context can be restored automatically by libgdx framework. And in my case, everything is OK with the real phone 4.0.3. But when I test with Android 2.x, it doesn't work well, just return me a white blank:((.
Isn't it true that i can leave restoring OpenGL context to libgdx? Could you please share your experiences with this? Or libgdx just can't work with Android versions lower than 4.x?( I use Opengl 1.0).
See http://www.badlogicgames.com/wordpress/?p=1073. The post is from 2010, and so it talks in about some future features that are now current (TextureAtlas and TextureRegion), and the point of the article is about how dynamically generated textures cannot be automatically managed by libGDX, but implicitly it describes the texture management problem, and how libGDX can be used to solve it in certain cases (basically libGDX needs to know how/where to reload your texture from).
libGDX should work fine on Android 2.x or 4.x.
Are you sure the underlying process is hanging around in both the 4.x and 2.x Android cases? Texture lossage is only a problem when an Activity exits and the Application stays alive until the Activity is restarted. If the Application exits, everything is re-initialized.
Related
I have an OpenGL ES app that works both on iOS and Android. Most of the code was written ages ago by another person and now I have to maintain it. OpenGL usage seems fairly simple (the game is 2D and uses only textured sprites in a simple manner). But I see two major differences in graphics code realization for iOS and Android:
1) iOS code contains this code:
glGenFramebuffersOES(1, &m_defaultFramebuffer);
glGenRenderbuffersOES(1, &m_colorRenderbuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, m_defaultFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_colorRenderbuffer);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, m_colorRenderbuffer);
and Android's one does not.
2) When Android app goes to background, all OpenGL textures are destroyed (glDeleteTextures) and EGL is shutdowned using eglTerminate. When app returns from sleep, EGL is re-initialized and textures are re-created.
iOS code does not do these things. It just pauses rendering loop by calling [m_displayLink setPaused:YES];
Other OpenGL-related code is the same for iOS and Android.
Everything works well on both platforms, but I want to have a full understanding of what's going on. Can anybody explain me a rationale behind these two differences?
1)
This is just a difference in the APIs. On iOS, you create your own framebuffer to render in to when the App starts. On Android the framebuffer is created automatically in GLSurfaceView, so the App doesn't need to create its own.
2)
On iOS, when your App goes to the background, the OpenGL context is preserved, which means all your textures and buffers are still there when you return it to the foreground.
Older versions of Android had only a single OpenGL context, so it was destroyed whenever your App went to the background (so that other Apps could then make use of it).
Later versions of Android do have the option to behave more like iOS by calling setPreserveEGLContextOnPause. However for this to work, the Android version has to be 3.x or above (API 11) and the device must support it also.
When it is not used or supported, the App must delete and re-create all it's OpenGL resources when going between background and foreground, which is what your App appears to be doing.
I've been given a task of designing an app in android with the UI created in OpenGL. The reason for this approach is the fact that the app will be a port from iPhone and Android does not have such smooth animations and graphics as IOS.
I have experience in Android development but I'm totaly new to OpenGL.
Is that approach reasonable to create GUI in OpenGL? If not, why? If yes, how do I start?
Is your application a game? because if not, I think using OpenGl just for creating a fancy UI might be too much. It leaves the door open to do things inefficiently, and probably, get a lot of bugs.
You can get a lot fo smootth animations using the different animations of Android.
If you still want to go with OpenGl, I will first advice you to start with Android Documentation
I am a fairly "newb" Android developer, and I would like one of my first projects to be a live wallpaper, however I am conflicted on whether I should be focusing on Canvas or OpenGL for it. Being new to this I know I should master Canvas first since it is easier to use, but I prefer to learn from real world projects that I have an interest in, even if it's a little backwards at times.
I have used both before in very basic ways, and I understand the general concepts to them, but I am not sure how they transfer over to the realm of live wallpapers. I figure that the full blown speed of OpenGL isn't required on a live wallpaper, since running it at max FPS would just run down the battery more than it necessary, but at the same time I am worried that using Canvas would cause lags and stutters when doing things like changing home screens.
I have been leaning towards using OpenGL ES 2.0, both to keep performance optimal and because my initial ideas for the wallpaper involve a lot of layering that I am not sure Canvas is capable of, but I'd like a more experienced developers opinion on whether or not all of the extra work involved in using OpenGL (especially in relation to live wallpapers, from what I've read) is worth it.
If you can get away with just drawing to a canvas (e.g. cube example in SDK), that's much less work. Because of the simplicity of the animation (no bitmaps), the cube is able to achieve a high frame rate without difficulty.
If you want to use OpenGL, you will need to use a supplemental package, such as GLWallpaperService, AndEngine, or RenderScript.
http://www.rbgrn.net/content/354-glsurfaceview-adapted-3d-live-wallpapers
http://www.andengine.org/forums/tutorials/live-wallpaper-template-t258.html
Browse the Android source code to see how the stock wallpapers (e.g. Grass, Galaxy) are implemented using RenderScript. This link may work, but no guarantees: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/4.1.1_r1/com/android/wallpaper/ (then scroll down to the wallpapers)
Moonblink has discontinued his project, but if you're really keen, you can try researching his work (Substrate) starting here: http://code.google.com/p/moonblink/source/browse/wiki/Setup.wiki
I ended up using OpenGL as halfway through the project, canvas drawing proved to be too slow for what I was trying to achieve. Using OpenGL caused a massive performance boost. Unfortunately I had to refactor my code, so I would reccomend using OpenGL from the start. Dirty rendering is supported by OpenGL as well as the wallpaperservice's structure doesn't rely on the way you render things so you would still be able to create a wallpaper that doesn't drain the battery. Actually a well programmed wallpaper doesn't render when it's hidden. As the wallpapers shipped with android don't follow that pattern, live wallpapers now have the bad name of being battery suckers. Really a shame..
I want to create a simulation game and a main component of this simulation will be a 2D map (topographical/navigation map), which shall have different layers (objects are moving on the map, using of labels, you get it)
The question for me is now, shall I use OpenGL to accomplish this or is that not necessary? I have no special requirements apart of that the scrolling and zooming shall be smooth. The target platform are only Android tablets (so Android OS 3.0+).
Edit: To precise my question:
platform independence is not important for me
I'd like to go with the easiest way concerning implementation efforts
If and only if you're really targeting Honeycomb specifically, then don't bother with OpenGL... and I say that as a reasonably experienced OpenGL programmer who's done some cool things with it on Android.
My reasoning is that, starting with Honeycomb, the normal Canvas-based APIs are hardware-accelerated too. Typically the only real reason for using OpenGL was greatly increaased performance, but that is no longer the case.
Or so the theory goes... I've yet to see actual Honeycomb hardware and run comparative tests. What I do know is that the Honeycomb emulator shows triangular tearing everywhere, strongly suggesting the whole desktop is now going through the GL pipeline.
If you have solid experience with OpenGL go with it. If not try some performance tests before you really decide if you invest time to learn it or if you use the good old simple 2D canvas drawing...
I'm not an expert on OpenGL + android (or any other mobile devices), but I think you will get better results (more FPSs, better drawing and animation options, etc) using OpenGL.
If you're used to non-OpenGL android development and are new to OpenGL it would be easier develop the game without using OpenGL. But before you choose this option, be aware that it should be a better option to use OpenGL if you aim to achieve beautiful/good performance graphics!
In short, if you master "regular" android development and prefer to build something good enough in a short time, stay "regular". Otherwise, I advice you to go for OpenGL.
I am almost done creating a game for android using a port of irrlicht 3d engine to android.
All code except a minimal frame work to make the native calls and play sounds is written in C++.
Even the opengles display is created in c++ code using eglGetDisplay and eglCreateWindowSurface
The problem I need to solve is that when home is pressed then relaunch the game the screen is all white.
From other answers I have found that the opengl context is lost then recreated when onSurfaceCreated is called. I thought that I could just reload textures but that seams to work for only some textures. Also the background color is changed which is not a resource.
It seams I would have to completely restart the game but this could be really annoying to a user.
the port of quake 3 has notes about this problem be has no solution.
Is there a example anywhere of a game written in native code which correctly handles this situation?
The way I handled the situation is to recreate everything. I made sure that all generated stuff like textures and buffers where deleted before recreating everything as if it happened for the first time.