Thursday, January 22, 2009

Android 3D graphics and SurfaceView

If you want to use OpenGL/ES, you have to use a SurfaceView class. The problem is that there are various parameters for the SurfaceView class. This, for example may work fine in the emulator:getHolder().setType(android.view.SurfaceHolder.SURFACE_TYPE_NORMAL);

on a real device, however, you may get a blank screen, or very slow redraws, so you should use this:getHolder().setType(android.view.SurfaceHolder.SURFACE_TYPE_GPU);

or even this:getHolder().setType(android.view.SurfaceHolder.SURFACE_TYPE_HARDWARE);

I think that this particular blog entry is wrong. The apk 1.0.4 beta, uses the line getHolder.setType(SURFACE_TYPE_GPU); only. This works on the G1 and on most emulator setups and should be used. However, it did not work correctly in an ubuntu linux emulator setup. It works fine on windows and macosx setups though. I will update the post when I have more information on the matter.