LibGDX,OpenGL 2.0和纹理必须是2的幂? [英] LibGDX, OpenGL 2.0 and textures having to be powers of two?

查看:138
本文介绍了LibGDX,OpenGL 2.0和纹理必须是2的幂?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在使用OpenGL 2.0和libGDX时,我的纹理图像必须是2的幂.这是在此页面上声明的 https://github.com/libgdx/libgdx/wiki/纹理,-textureregion-and-spritebatch .

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"))
);

此图像的尺寸为133 x 23,显然不是2的幂.但是,一切都很好.

This image has dimensions of 133 x 23 which obviously are not powers of two; but, all is fine.

在我的游戏中,我正在使用AssetManager将纹理等加载到我的游戏中,但是我发现我使用的纹理的大小必须为^ 2,例如128x32、512x512等,否则它们不起作用?

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);
        }
    }

纹理为512x512,如果不是,则不会显示textureRegion.

The texture is 512x512 and if it is not then the textureRegion does not display.

为什么某些纹理必须具有2的幂,而另一些则没有?

Why is there a difference in some textures having to be powers of two in size and some others do not?

推荐答案

严格的2(POT)大小幂要求仅适用于OpenGL ES1.x.自libGDX版本1.0.0起,libGDX不再支持此版本的OpenGL ES.因此,不再有对纹理的严格POT要求.

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.

但是,取决于GPU,非POT纹理尺寸可能不支持某些功能(例如,纹理环绕).而且,实际上,非POT大小的纹理可能(将)使用与最接近的较大POT大小相同的内存量.

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.

由于这些原因,并且由于无论如何都应将多个纹理打包到图集上,因此强烈建议始终使用POT大小的纹理.

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.

另请参见:如果那不能回答您的问题,请考虑改写您的问题,并用它们不起作用"来解释您的意思.

If that doesn't answer your question, then please consider rephrasing your question and explain what you mean with "they do not work".

这篇关于LibGDX,OpenGL 2.0和纹理必须是2的幂?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆