OpenGL:精确的纹理可能吗?
这是针对使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然,只需禁用过滤即可,这是通过将 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.
正如 Matias 之前所说,一件事是将
GL_MIN_FILTER
和GL_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
andGL_MAG_FITLER
toGL_NEAREST
(viaglTexParameter*
).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 ofGL_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.