OpenGL texture tilted

有些话、适合烂在心里 提交于 2019-12-09 20:09:34

问题


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.


回答1:


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!