OpenGL纹理倾斜 [英] OpenGL texture tilted
问题描述
当我在OpenGL中加载纹理并且每个像素有一个(GL_ALPHA
)或三个分量(GL_RGB
)时,该纹理看起来是倾斜的.是什么使这种情况发生的?
When I load a texture in OpenGL and this has one (GL_ALPHA
) or three components per pixel (GL_RGB
), the texture appears tilted. What makes this happen?
作为其他细节,关系的宽度/高度似乎会受到影响.例如,正确映射1920x1080(16/9)的图像时,1366x768(683/384)的图像会出现倾斜.
As additional detail, the relation width/height seems to affect. For example, an image of 1366x768(683/384) appears tilted while an image of 1920x1080(16/9) is mapped correctly.
推荐答案
这可能是填充/对齐问题.
This is probably a padding/alignment issue.
GL默认情况下期望将像素行填充为4字节的倍数.具有1字节或3字节宽像素的1366宽纹理自然不会对齐4字节.
GL, by default, expects rows of pixels to be padded to a multiple of 4 bytes. A 1366 wide texture with 1 byte or 3 byte wide pixels, will not be naturally 4 byte aligned.
可能的解决方法是:
- 使用(例如)
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
告诉GL如何包装纹理
- 更改纹理的尺寸,以使填充区域匹配而不更改任何内容
- 更改纹理的加载,以使填充与GL期望的一致
- Tell GL how your texture is packed, using (for example)
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- Change the dimensions of your texture, such that the padding matches without changing anything
- Change the loading of your texture, such that the padding is consistent with what GL expects
这篇关于OpenGL纹理倾斜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!