Hi, On Dec 26, 5:00 am, Toothy Bunny <[email protected]> wrote: > Hi All, > When designing a 3D game running on Android, we need to enter into 3D > (OpenGL) rendering and quit back to 2D rendering from time to time, > like this control flow: game title page (2D) -> game main menu (2D) -> > game window (3D / OpenGL) -> game main menu (2D). > We have made this working well on the emulator by following the design > pattern required by SurfaceView: > > 1) For 2D rendering: > Canvas c = _surfaceHolder.lockCanvas(); > //Do 2D rendering with canvas > _surfaceHolder.unlockCanvasAndPost(c); > > 2) After entering 3D (OpenGL) rendering: > egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext); > //Do OpenGL rendering > egl.eglSwapBuffers(eglDisplay, eglSurface);
Unfortunately, It is not currently possible to mix and match lockCanvas () with eglSwapBuffers(). I would recommend to simply use a regular view to do the 2D rendering. You can have a regular view on top of the SurfaceView you use for OpenGL (use a layout to stack them up), and simply show and hide the "2D" view when needed. This requires that the 2D rendering be done in the UI thread though; but it will be more efficient and this has the advantage that you can use any widget you want (like buttons). > This works well on the emulator. However on T-Mobile G1 phone, > entering 3D (OpenGL) from 2D does not have any problem, but when exit > 3D back to 2D, the G1's screen content remained with the last OpenGL > rendering and no any 2D rendering can be added on the Surface. > I think the reason is because we set the Surface type as > "SurfaceHolder.SURFACE_TYPE_GPU" when we create the surface. When I > quit from OpenGL, I tried to change the surface type back to > "SurfaceHolder.SURFACE_TYPE_NORMAL" but it general IllegalArgument > Exception. I guess it is because Android Surface does not allow to > change its type dynamically. Exact. > So my question is: how can we properly exit from OpenGL and make the > Surface work again with all 2D rendering? Is there a way to re-create > the surface of the View object? > > By the way, my OpenGl clean-up code is exactly same as the > GLSurfaceView sample code, it should have any problem. > > Many thanks for any suggestions! > Hongkunwww.omnigsoft.com I hope this helps. Mathias --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

