libgdx:NPOT问题的解决办法

android上画图可以使用Opengl es,分两个不兼容的版本:opengl es1.x, opengl es 2.0,使用时它们之间的一个重要区别就是:opengl es 1.x的图片大小必须是2的整数次幂,而opengl es 2.0则无此要求。看有些文档里说:libgdx只支持2的整数次幂的图像,那应该是opengl es1.x的版本。

 

在编译一个开源游戏freegemas时,代码在Lwjgl的pc上运行正常,而编译成apk在android真机或模拟器上运行时就崩溃,报错:“图像大小必须是2的整数次幂”。但是:“libgdx's wiki said:  we explicitely request to use OpenGL ES2.0. This allows us to load images that do not have a power-of-two size, a necessity for images to be used in OpenGL ES 1.0. opengl es 2.0's specifition shows it suppots NPOT images.”

在游戏中已通过“"config.useGL20 = true;".”指定使用opengl es2.0,而且android(4.0)系统已确定支持opengl es2.0,那为什么还是报错呢?

 

经查找,确认如下信息:

(1)android系统对opengl es的支持情况:
opengl es 1.0------------------->andoid 1.0-2.1(api 7)
opengl es 2.0------------------->android 2.2(api 8)以上
http://developer.android.com/guide/topics/graphics/opengl.html#compatibility

 

(2)emulator only support opengl es 1.0(所有版本的android系统)
“Unfortunately, the Android emulator does not support OpenGL ES 2, so you’ll need access to an actual Android device in order to run the tutorial. Most recent devices should support OpenGL ES 2 these days, so all you need to do is enable developer mode and hook the phone up to your machine.”

http://www.learnopengles.com/android-lesson-one-getting-started/

而且从logcat的调试信息,也可以看到,在模拟器上即使是4.2的系统,也只有open es 1.0可用

 

(3)使用libgdx的gdx-setup-ui.jar创建项目时,选中:
show advance settings->targetSDkVersion>默认值是17,但adt中并没有安装该版本的sdk,所以之后会被覆盖为7(android2.1),该版本只支持opengl es1.0
设置为>=8的值即可(对应的sdk必须已安装好)。


最后可以在android项目的project.properties文件中查看所使用的sdk版本。

(4)
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
cfg.useGL20 = true;


so,we can not debug app on emulator if the iamges it NPOT, only support real devices(android 2.2+)

posted @ 2012-12-31 21:14    阅读(810)  评论(0编辑  收藏  举报