问题
I understand that when using OpenGL 2.0 and libGDX my texture images have to be of a power of two. This is stated on this page https://github.com/libgdx/libgdx/wiki/Textures,-textureregion-and-spritebatch.
One thing that I cannot understand is that this is not always true. I am creating an app that has a splash screen and the texture that I use is loaded directly in the class declaration (the Screen) like below;
private TextureRegion textureRegion = new TextureRegion(
new Texture(Gdx.files.internal("images/splashLogo.png"))
);
This image has dimensions of 133 x 23 which obviously are not powers of two; but, all is fine.
In my game I am using the AssetManager to load textures etc into my game, but I have found that the textures I use have to be of size ^2 such as 128x32, 512x512 etc or they do not work?
An example set of textures from my asset manager is below;
shapes = TextureRegion.split(Assets.assetManager.get("images/shapeSprite.png", Texture.class), 64, 64);
for (TextureRegion[] shapeSet: shapes) {
for (TextureRegion shape: shapeSet) {
shape.flip(false, true);
}
}
The texture is 512x512 and if it is not then the textureRegion does not display.
Why is there a difference in some textures having to be powers of two in size and some others do not?
回答1:
The strict power of two (POT) size requirement was only for OpenGL ES 1.x. libGDX doesn't support this version of OpenGL ES anymore since libGDX version 1.0.0. So there isn't a strict POT requirement for textures anymore.
However, depending on the GPU, some features (e.g. texture wrapping) might not be supported for non-POT texture sizes. Also, in practice, a non-POT sized texture might (will) use the same amount of memory as the nearest bigger POT size.
Because of these reasons and since multiple textures should be packed onto an atlas anyway, it is strongly advised to always use POT sized textures.
See also: Is there any way to ignore libgdx images Limitation? (images must be power of two)
If that doesn't answer your question, then please consider rephrasing your question and explain what you mean with "they do not work".
来源:https://stackoverflow.com/questions/27982074/libgdx-opengl-2-0-and-textures-having-to-be-powers-of-two