问题
I have a class which implements GLSurfaceView.Renderer and uses Open GL ES 2.0, and works perfectly as a standard application.
However I'd like to expand this so that its a live wallpaper. Naturyally I've got a service class which exteds WallPaperservice, and in turn a engine class which extends WallpaperService.Engine.
In the normal version of the code I can just do
mGLSView = new GLSurfaceView(this); // in the engine this becomes 'new GLSurfaceView(getBaseContext());'
mGLSView.setEGLContextClientVersion(2);
mGLSView.setRenderer(new myRenderer());
setContentView(mGLSView);
However in the 'Engine' you cannot call setContentView. Presumably I need to pass the surface into the GLSurfaceView somehow, but I really cant see how. Every example or tutorial that I've found uses OpenGL 1, and because I'm quite new to this I cant quite figure out how to adapt them for 2.0.
So does anyone know of a simple example of a live wallpaper using OpenGL ES 2.0? Or a good pointer on where to readup?
Thanks,
回答1:
Ok, got it! If you use the source from http://www.rbgrn.net/content/354-glsurfaceview-adapted-3d-live-wallpapers (And thank you very much to Robert Green for this!!)
For whatever reason I had to fix a few syntax errors, I suspect this is from having a newer version of Eclipse or whatever since the original was written.
To enable OpenGL ES 2.0 though, you need to make two changes. In the constructor of ComponentSizeChooser add
EGL10.EGL_RENDERABLE_TYPE, 4,
To the super call. Also in createContext in DefaultContextFactory replace the null with
new int[] { 0x3098, 2, EGL10.EGL_NONE }
And that should have you enabled for GL ES 2.0.
Also, additionally, on his webpage, he has 'setRenderMode(RENDERMODE_WHEN_DIRTY);' I suspect most will want this to be 'setRenderMode(RENDERMODE_CONTINUOUSLY);'
Full code is available Here.
来源:https://stackoverflow.com/questions/11377973/how-to-convert-an-open-gl-es-2-0-application-to-a-live-wallpaper