Is there any way to ignore libgdx images Limitatio

2019-05-09 23:37发布

问题:

In libgdx framework we can only use images power of two (64x256, 128x32, etc) Because OpenGL requires it.

Is there any good way to "pass" this limitation?
For example: Use images 800x480.

回答1:

Do set Texture.setEnforcePotImages(false); and you do not have the limitation anymore. So it's not true that you just can use pictures with the size power of two. It's just a "can have" not a "must have".

Regards



回答2:

You can use non pot textures, e.g. by using opengl es2.0. But it is good practice to at least try to use pot textures. For example by packing multiple images into a single texture. This also reduces the amount of texture switches. See: http://code.google.com/p/libgdx/wiki/TexturePacker.



回答3:

Do this before loading the image:

GLTexture.setEnforcePotImages(false);

This will ignore the power 2 check.



回答4:

The Best practice is to not to use your images directly. Instead use TexturePacker tool avalilable in LibGdx nightlies to generate Image Atlas. To know more :- https://github.com/libgdx/libgdx/wiki/Texture-packer



回答5:

For some textures you can just make it a power of two.

For a background of 800 X 480 you can just make it 1024 x 512 by adding transparent space to the top and to the right. Then when drawing the texture just simply place in on the origin. (The left hand corner) One thing to note is that this technique causes resulting files to end up a tad larger.

Before resizing (800 X 480)

After resizing (1024 x 512)

This, of course, can be easily done in GIMP. Go to Image -> Canvas Size. Then enter the desired width and height. Gimp will place the image in the left upper corner of the transparent space, but we want it in the lower left corner. To move it simply enter the highest Y offset. (You can enter too larger of a number and Gimp will correct it)



回答6:

use open gl2.0 for removing this limitation