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?
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, 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.
Possible fixes for this are:
- 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
来源:https://stackoverflow.com/questions/15983607/opengl-texture-tilted