iPhone OpenGL ES 2.0 - 像素完美纹理 [英] iPhone OpenGL ES 2.0 - Pixel Perfect Textures

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

问题描述

如何让我的纹理与 OpenGL ES 2.0 中像素完美图形的屏幕像素对齐?这对于我正在处理的使用像素艺术图形的项目至关重要.对此的任何帮助都会很棒!

How can I get my textures to align with the screen pixels for pixel perfect graphics in OpenGL ES 2.0? This is critical for a project I'm working on which uses pixel art graphics. Any help on this would be great!

推荐答案

在这里查看我的答案:像素空间中的OpenGL纹理坐标

这已被问过几次,但我手头没有链接,所以一个快速而粗略的解释.假设纹理是 8 像素宽:

This has been asked a few times, but I don't have the links at hand, so a quick and rough explanation. Let's say the texture is 8 pixels wide:

 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
 ^   ^   ^   ^   ^   ^   ^   ^   ^
0.0  |   |   |   |   |   |   |  1.0
 |   |   |   |   |   |   |   |   |
0/8 1/8 2/8 3/8 4/8 5/8 6/8 7/8 8/8

数字表示纹理的像素,条形表示纹理的边缘,并且在最近过滤像素之间的边界的情况下.但是,您想击中像素的中心.所以你对纹理坐标感兴趣

The digits denote the texture's pixels, the bars the edges of the texture and in case of nearest filtering the border between pixels. You however want to hit the pixels' centers. So you're interested in the texture coordinates

(0/8 + 1/8)/2 = 1/(2 * 8)

(0/8 + 1/8)/2 = 1 / (2 * 8)

(1/8 + 2/8)/2 = 3/(2 * 8)

(1/8 + 2/8)/2 = 3 / (2 * 8)

...

(7/8 + 8/8)/2 = 15/(2 * 8)

(7/8 + 8/8)/2 = 15 / (2 * 8)

或者更一般地说,对于 N 宽纹理中的像素 i,正确的纹理坐标是

Or more generally for pixel i in a N wide texture the proper texture coordinate is

(2i + 1)/(2N)

(2i + 1)/(2N)

但是,如果您想将纹理与屏幕像素完美对齐,请记住您指定的坐标不是四边形的像素,而是边缘,根据投影,边缘可能与屏幕像素边缘对齐,而不是中心,因此可能需要其他纹理坐标.

However if you want to perfectly align your texture with the screen pixels, remember that what you specify as coordinates are not a quad's pixels, but edges, which, depending on projection may align with screen pixel edges, not centers, thus may require other texture coordinates.

这篇关于iPhone OpenGL ES 2.0 - 像素完美纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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