OpenGL 纹理倾斜 [英] OpenGL texture tilted

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

问题描述

当我在 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?

作为额外的细节,关系宽度/高度似乎有影响.例如,1366x768(683/384) 的图像看起来倾斜,而 1920x1080(16/9) 的图像被正确映射.

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 预期一致

这篇关于OpenGL 纹理倾斜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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