优化动态壁纸
我发现每当我创建动态壁纸时,事情就会开始滞后。例如,在屏幕之间切换时,动画滞后。在我见过的许多其他壁纸中,那些对图形要求更高的壁纸,实际上没有延迟。据我所知,OpenGL 似乎能够比 Canvas 更快地渲染图形。
我只想以二维方式绘制。所以我认为 onDrawFrame 方法中的情况是这样的。 由于 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
}
但在此之后,我不知道如何绘制位图或线条,这基本上是我当前项目所需的全部。有人可以告诉我如何完成这些简单的任务吗?另外,如果我完全关闭,有人可以告诉我我做错了什么吗?
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 simple tasks? Also, if I'm completely off, can someone tell me what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用补充包才能在动态壁纸中使用 OpenGL。两个明显的候选者是:
GLWallpaperService (https://github.com/markfguerra/GLWallpaperService)
AndEngine (http://code.google.com/p/andenginelivewallpaperextension/)
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/)
乔治是对的,如果你还没有,你绝对应该使用 https://github.com/markfguerra/GLWallpaperService 用于您的 GL/壁纸后端。
另外,您不应该在 onDraw 中设置投影(每帧都会发生),您应该在 onSurfaceChanged() 中设置投影(因为您只需要在视图更改时执行此操作),这可能会导致您的滞后重新看到。查看本教程系列 弄湿你的脚。
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.