开发者

Optimizing Live Wallpapers

I find that whenever I'm creating a live wallpaper, things begin to lag. For example, when switching between the screens, the animation lags. In many other wallpapers I've seen, ones with much more demanding graphics, there is literally no lag. From what I can see, OpenGL seems to be able to render graphics much faster than the Canvas can.

I want to draw solely in 2D. So I think it goes something like this in the onDrawFrame method. thanks to http://basic4gl.wikispaces.com/2D+Drawing+in+OpenGL

public void onDrawFrame(GL10 gl)
{
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glOrthox(0, w, h, 0, 0, 1);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glTranslatef(.375f, .375f, 0);
    gl.glDisable(GL10.GL_DEPTH_TEST);
    gl.glClearColorx(162,205,239, 255);//In place of gl.glClear() because I want a differently colored background
}

But after this, I have no idea how to draw bitmaps or lines, which are essentially all I need for my current project. Can someone please tell me how to do these sim开发者_高级运维ple tasks? Also, if I'm completely off, can someone tell me what I'm doing wrong?


You need to use a supplemental package to work with OpenGL within live wallpaper. Two obvious candidates are:

GLWallpaperService (https://github.com/markfguerra/GLWallpaperService)
AndEngine (http://code.google.com/p/andenginelivewallpaperextension/)


George is right, if you aren't already, you should definitely be using https://github.com/markfguerra/GLWallpaperService for your GL/wallpaper backend.

Also, you shouldn't be setting up your projections in onDraw (which happens every frame), you should do that in onSurfaceChanged() (since you only need to do it when your view changes), which may be causing the lag you're seeing. Check out this tutorial series to get your feet wet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜