尺寸不是 2^x 的 openGL 纹理

发布于 2024-07-10 09:43:18 字数 114 浏览 5 评论 0原文

我正在尝试在 openGL 环境中显示图片。 图片的原始尺寸是3648x2432,我想用256x384的图像显示它。 问题是,384 不是 2 的幂,当我尝试显示它时,它看起来很拉伸。 我该如何解决这个问题?

I'm trying to display a picture in an openGL environment. The picture's origninal dimensions are 3648x2432, and I want to display it with a 256x384 image. The problem is, 384 is not a power of 2, and when I try to display it, it looks stretched. How can I fix that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

北城孤痞 2024-07-17 09:43:18

据我所知,有三种方法可以做到这一点 -

  • 艾伯特建议的方法(调整大小直到适合)。
  • 将纹理细分为 2**n 大小的矩形,并以某种方式将它们拼凑在一起。
  • 看看是否可以使用GL_ARB_texture_non_power_of_two。 不过,最好避免它,因为它看起来像是 Xorg 特定的扩展。

There's three ways of doing this that I know of -

  • The one Albert suggested (resize it until it fits).
  • Subdivide the texture into 2**n-sized rectangles, and piece them together in some way.
  • See if you can use GL_ARB_texture_non_power_of_two. It's probably best to avoid it though, since it looks like it's an Xorg-specific extension.
旧时模样 2024-07-17 09:43:18

您可以调整纹理的大小,使其为2的幂(倾斜纹理,以便当它映射到对象上时它看起来是正确的)。

You can resize your texture so it is a power of two (skew your texture so that when it is mapped onto the object it looks correct).

上课铃就是安魂曲 2024-07-17 09:43:18

ARB_texture_rectangle 可能就是您正在寻找的。 它允许您绑定到 GL_TEXTURE_RECTANGLE_ARB 而不是 GL_TEXTURE_2D,并且您可以加载非 2 次幂维度的图像。 请注意,纹理坐标的范围为 [0..w]x[0..h],而不是 [0..1]x[0..1]。

ARB_texture_rectangle is probably what you're looking for. It lets you bind to GL_TEXTURE_RECTANGLE_ARB instead of GL_TEXTURE_2D, and you can load an image with non power-of-2 dimensions. Be aware that your texture coordinates will range from [0..w]x[0..h] instead of [0..1]x[0..1].

霊感 2024-07-17 09:43:18

如果 GL_EXT_texture_rectangle 为 true,则在 glEnable() 和 GLBindTexture() 调用中使用 GL_TEXTURE_RECTANGLE_EXT 作为第一个参数。

If GL_EXT_texture_rectangle is true then use GL_TEXTURE_RECTANGLE_EXT for the first param in glEnable() and GLBindTexture() calls.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文