11

So, i've made the raindrop tutorial project by libGDX. However, when i attempt to deploy it to the emulator i get an error saying that the image is not a power of 2. But i did re-size the images to be 48X48 using GIMP (as the tutorial had suggested). I believe he had added in some code to ensure that it would be possible to add in images that were not necessarily a power of two?

Does anyone know how i would fix this? Making it a power of two is a bit limiting.. isn't it? I followed the tutorial very closely! So... i'm not sure where to go from here. Noob at libGDX.

LogCat Dump:

06-11 00:22:50.942: W/dalvikvm(545): threadid=11: thread exiting with uncaught exception (group=0x409c01f8)
06-11 00:22:50.952: E/AndroidRuntime(545): FATAL EXCEPTION: GLThread 72
06-11 00:22:50.952: E/AndroidRuntime(545): com.badlogic.gdx.utils.GdxRuntimeException: Texture width and height must be powers of two: 48x48
06-11 00:22:50.952: E/AndroidRuntime(545):  at com.badlogic.gdx.graphics.Texture.uploadImageData(Texture.java:197)
06-11 00:22:50.952: E/AndroidRuntime(545):  at com.badlogic.gdx.graphics.Texture.load(Texture.java:179)
06-11 00:22:50.952: E/AndroidRuntime(545):  at com.badlogic.gdx.graphics.Texture.create(Texture.java:159)
06-11 00:22:50.952: E/AndroidRuntime(545):  at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:133)
06-11 00:22:50.952: E/AndroidRuntime(545):  at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:122)
06-11 00:22:50.952: E/AndroidRuntime(545):  at com.badlogic.drop.Drop.create(Drop.java:38)
06-11 00:22:50.952: E/AndroidRuntime(545):  at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:292)
06-11 00:22:50.952: E/AndroidRuntime(545):  at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1455)
06-11 00:22:50.952: E/AndroidRuntime(545):  at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)
06-11 00:22:51.041: I/AndroidInput(545): sensor listener tear down
06-11 00:22:51.041: I/AndroidGraphics(545): Managed meshes/app: { }
06-11 00:22:51.041: I/AndroidGraphics(545): Managed textures/app: { }
06-11 00:22:51.041: I/AndroidGraphics(545): Managed shaders/app: { }
06-11 00:22:51.041: I/AndroidGraphics(545): Managed buffers/app: { }
BigBug
  • 6,202
  • 23
  • 87
  • 138
  • 2
    32 and 64 are powers of two. 48 is not. –  Jun 11 '12 at 00:27
  • 1
    The tutorial had said that we could change it to 48x48 though. I think he had added some code in there to ensure that it wouldn't break. Is there a way of doing that? So that the images don't necessary have to be a power of two? Like i said, i re-sized the images to 48X48 as he suggested in the tutorial... weird :S – BigBug Jun 11 '12 at 00:29
  • http://code.google.com/p/libgdx/wiki/SimpleApp – BigBug Jun 11 '12 at 00:35
  • 5
    he states "Note: we explicitely request to use OpenGL ES 2.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." – BigBug Jun 11 '12 at 00:36
  • 2
    Using powers of two might seem limiting, but in reality you won't find it a problem. To get around the limitation, pack your textures (there's a texture packer in libgdx) into one large texture and access each individual texture region using a texture atlas. This is a good thing, as switching textures is a relatively slow operation for OpenGL. – R Hyde Jun 11 '12 at 06:54

3 Answers3

30

48x48 is not a power of two. The app requires OpenGL ES 2.0 as stated in the text. The standard emulator only runs OpenGL ES 1.0. You can rescale the image to 32x32, then everything will work as expected on OpenGL ES 1.x as well.

I'd recommend not using the emulator for testing OpenGL ES apps. Use a real device instead.

badlogic
  • 3,049
  • 1
  • 21
  • 12
  • Good answer. This was driving me nuts because the app I was working on would run on the device but not the emulator. Thanks! Also, great framework dude! Keep up the good work! – LoveMeSomeCode Nov 27 '12 at 03:23
17

You can stop it from enforcing the power of two requirement by setting the following line of code in your game class in the create() method:

Texture.setEnforcePotImages(false);
sngreco
  • 1,138
  • 11
  • 16
  • Thanks - This is a handy solution .. Is it safe to use this, even on target platforms that support OpenGL 1.0? I'd prefer this solution because I'm developing a 2D-game and therefore, I'm only using OpenGL's orthogonal drawing mode. Providing all Image dimensions with a power of 2 seems too restricting for me here in many cases. – Christopher Stock Sep 09 '13 at 14:41
  • 1
    Don't know what the difference is but I had to write this to make it work: `GLTexture.setEnforcePotImages(false);` – Mikaël Mayer Aug 23 '14 at 13:22
0

this worked for me change all "GL10" imported from "com.badlogic.gdx.graphics.GL10" to "GL20" imported from "com.badlogic.gdx.graphics.GL20"

viet
  • 1