OpenGL要求纹理尺寸为"2的幂". [英] OpenGL requires texture dimensions to be of "Power of Two"

查看:710
本文介绍了OpenGL要求纹理尺寸为"2的幂".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试使用电晕库在OpenGL上下文中加载纹理. OpenGL要求纹理具有2的幂!!

1.为什么不使用其他纹理尺寸?为什么只需要幂二的纹理?

2.如何将纹理转换为2的幂?

谢谢和问候,
GPUToaster.

Hi,

I''m trying to load a Texture in an OpenGL context using corona library. OpenGL requires a texture to be of power of two!!

1. Why not other texture dimensions? Why it requires only textures of power two?

2. How to convert a texture to power of two?

Thanks and Regards,
GPUToaster.

推荐答案

GPUToaster写道:
GPUToaster wrote:

1.为什么不使用其他纹理尺寸?为什么只需要幂2的纹理?

1. Why not other texture dimensions? Why it requires only textures of power two?



我认为这样做是出于优化的原因.不太清楚为什么.据我所知,加载大小不为2的幂的纹理将在某些计算机上有效,但在其他计算机上则不行(在这种情况下,将显示白色矩形).




I think it does that for optimization reasons. Not really sure why. As far as I know, loading a texture which is has not a size of power of two will work on certain computers but not on other computers (in which case, a white rectangle will be displayed instead).


GPUToaster写道:
GPUToaster wrote:

2.如何将纹理转换为2的幂?

2. How to convert a texture to power of two?



转换很容易:只需在绘图程序(例如绘画)中打开图片并增加图片的大小,以使其宽度和高度为2的幂(16、32、64、128,...),然后保存.您的右侧和底部会有一些空白.

现在,当您要绘制纹理时,您只需要绘制实际包含纹理的部分,而无需未使用"空间.如果您愿意,可以看一下我关于OpenGL系列的第二篇文章,那里有一个有关如何做的示例.



Converting it is easy: simply open the picture in a drawing program (e.g. paint) and increase the size of the picture so that its width and height are a power of two (16, 32, 64, 128, ...) and then save it. You will have some white space on the right and bottom.

Now, when you want to draw your texture, you have to draw only the part which is actually containing your texture, without the ''unused'' space. If you want, you can have a look at my second article on the OpenGL series, there''s an example on how to do it there.


这篇关于OpenGL要求纹理尺寸为"2的幂".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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