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

查看:84
本文介绍了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!

推荐答案

在这里查看我的答案:

See my answer here: OpenGL Texture Coordinates in Pixel Space

已经问过几次了,但是我手边没有链接,因此请快速粗略地解释一下.假设纹理的宽度为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天全站免登陆