OpenGL:精确的纹理可能吗?

发布于 2024-09-27 09:49:34 字数 139 浏览 2 评论 0原文

这是针对使用 OpenGL 的 2D 游戏:

使用 OpenGL 是否可以显示绝对未过滤、未拉伸或模糊的纹理?

这样,当我有 BMP 并将其转换为 OpenGL 纹理,然后检索该纹理并将其转换回来时,我没有任何修改或质量/数据丢失?

This is for a 2D game with OpenGL:

Is it with using OpenGL possible to display a texture absolutely unfiltered, not streched or blurred?

So that when I have a BMP and convert it into an OpenGL texture, and then retrieve that texture and convert it back, I have no modifications or quality / data loss?

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

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

发布评论

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

评论(2

无尽的现实 2024-10-04 09:49:34

当然,只需禁用过滤即可,这是通过将 GL_MIN_FILTER 和 GL_MAG_FILTER 设置为 GL_NEAREST 来实现的。还要确保以适当的尺寸绘制纹理,以便纹素与像素的尺寸相同。

Sure, just disable filtering, that's made by setting the GL_MIN_FILTER and the GL_MAG_FILTER to GL_NEAREST. Also make sure that you draw the texture in a appropiate size so that texels are the same size as pixels.

终难遇 2024-10-04 09:49:34

正如 Matias 之前所说,一件事是将 GL_MIN_FILTERGL_MAG_FITLER 设置为 GL_NEAREST(通过 glTexParameter*)。

但对于像素完美渲染,还有另一件重要的事情 - 您不希望纹理重新缩放为 2 的幂。最简单的方法是通过绑定目标 GL_TEXTURE_RECTANGLE 而不是 GL_TEXTURE_2D 指定纹理。在此类绑定纹理上,纹理坐标并不像通常那样在 (0..1,0..1) 范围内,而是在 (0..w, 0..h) 范围内。通过这种方式,您可以轻松地按纹理元素建立索引。

As Matias said previously - one thing is to set GL_MIN_FILTER and GL_MAG_FITLER to GL_NEAREST (via glTexParameter*).

But for pixel-perfect rendering, there's another important thing- you don't want your texture to be rescaled to power-of-two. The easiest way is to specify the texture via the binding target GL_TEXTURE_RECTANGLE instead of GL_TEXTURE_2D. On such bound texture, the texture coordinates are not in range (0..1,0..1) as usually, but (0..w, 0..h) instead. You can have per-texel indexing easily this way.

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