使用纹理坐标的 OpenGL ES 1.1 Texel 到像素映射不起作用,我做错了什么?
编辑
好的,这个问题很老了。
在学习了一些 OpenGL ES 并进行测试后,我发现我的 iPhone 4 实际上使用了双倍分辨率的图像。如果我没记错的话,我必须将 OpenGL 上下文比例点设置为 2。
然后图像会显得清晰。
希望这可以帮助其他遇到同样问题的人。
最初的问题
我试图克制自己不要实际发布问题,并继续在互联网上搜索任何进一步的线索来解释为什么我的纹素到像素映射不起作用,但 OpenGL 被证明是一个需要正确处理的怪物。
OpenGL 开发环境:
iPhone 4
OpenGL ES 1.1
纵向模式下的屏幕宽度 = 320 像素(UIScreen 边界宽度)
纵向模式下的屏幕高度 = 480 像素(UIScreen 边界高度)
纹理图像宽度 = 480 像素(图像文件像素) 纹理图像高度 = 320 像素(图像文件像素)
您可以下载的资源:
Xcode 项目: http://www.chewedon.com/OGL.zip cheedon.com/OGL.zip
使用的纹理图像: http://img.photobucket.com/albums/v639/Ryu_Kaiser /serah.png
问题:
我一直在研究将纹素映射到像素的问题,以便最终绘制的纹理将像现在这样清晰锐利在 Photoshop 中,即像素和纹理纹理像素之间的像素完美映射。
我知道问题在于纹素中心并不位于像素中心之上。我还了解修复它的解决方案是将纹素移动半个纹素(或者是像素?),以便纹素将直接位于顶部。
我尝试像这样设置纹理坐标数组:(
const GLfloat texCoords[] =
{
0.0 + (0.5 / 480.0), 1.0 + (0.5 / 320.0),
1.0 + (0.5 / 480.0), 1.0 + (0.5 / 320.0),
0.0 + (0.5 / 480.0), 0.0 + (0.5 / 320.0),
1.0 + (0.5 / 480.0), 0.0 + (0.5 / 320.0)
};
同样,我也尝试设置顶点坐标。根据我读过的一些示例,他们说您可以更改纹理坐标或顶点坐标)
如果我使用纹理坐标 0.0 到 1.0 运行我的应用程序,纹理在 iPhone 模拟器中看起来很完美,但如果我在 iPhone 上运行应用程序,纹理会有非常轻微的模糊。
我做错了什么?
我是否需要将纹理坐标乘以屏幕宽高比因子?
我已经上传了我用来绘制 OpenGL 场景的 Xcode 项目和我使用的纹理图像(上面链接)。
干杯。
EDIT
OK, this question is old.
What I found out after learning some OpenGL ES and testing is my iPhone 4 was actually using double the resolution image. If I remember correctly, I had to set my OpenGL context scale point to 2.
Then the image appears sharp.
Hope this helps anyone else having the same problem.
ORIGINAL QUESTION
I've tried to refrain myself from actually posting a question and keep searching the Internet for any further clues as to why my texel to pixel mapping isn't working out but OpenGL proves to be a monster of a thing to get right.
OpenGL Development Environment:
iPhone 4
OpenGL ES 1.1
Screen Width in Portrait mode = 320 pixel (UIScreen bound width)
Screen Height in Portrait mode = 480 pixel (UIScreen bound height)
Texture image width = 480 pixel (image file pixel)
Texture image height = 320 pixel (image file pixel)
Resources You Can Download:
Xcode project: http://www.chewedon.com/OGL.zip
Texture image used: http://img.photobucket.com/albums/v639/Ryu_Kaiser/serah.png
The Question:
I've been researching about the problem of mapping texels to pixel so that the final texture drawn will be crisp sharp like it is in Photoshop, i.e. a pixel perfect mapping between pixel and texture texels.
I understand the problem lies in the fact texel centers are not sitting ontop of pixel centers. I also understand the solution to fixing it is moving the texels by half a texel (or was it pixel?) so that the texel will sit directly ontop.
I've tried setting my array of texture coordinates like so:
const GLfloat texCoords[] =
{
0.0 + (0.5 / 480.0), 1.0 + (0.5 / 320.0),
1.0 + (0.5 / 480.0), 1.0 + (0.5 / 320.0),
0.0 + (0.5 / 480.0), 0.0 + (0.5 / 320.0),
1.0 + (0.5 / 480.0), 0.0 + (0.5 / 320.0)
};
(Similarly, I've also tried setting the vertices coordinate as well. According to some of the examples I've read, they say you can change the texture coordinate or vertices coordinate)
If I run my app using texture coordinates 0.0 to 1.0, the texture looks perfect in the iPhone simulator but if I run the app on my iPhone the texture has a very slight blur.
What am I doing wrong?
Do I need to multiply my texture coordinates by the screen width to height aspect ratio factor ?
I've uploaded my Xcode project I used to draw my OpenGL scene and the texture image I used (linked above).
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除了 Marcus 所说的之外,您应该从 1.0 中减去半个纹素,而不是相加。对顶点位置执行相同的操作(将下限添加一半,从上限减去一半)。您还应该确保使用纹理的宽度和高度作为纹素偏移,使用屏幕的宽度和高度作为位置偏移,而不是两者同时使用(当然,除非它们相等)。这应该会给你相当像素完美的纹理映射。
In addition to what Marcus said you should rather subtract half a texel from 1.0, instead of adding. And do the same (add half to lower bound, subtract half from upper bound) for the vertex positions. You should also be sure to use the texture's width and height for the texel offsets and the screen's width and height for the position offsets, not one for both (except if they're equal, of course). This should give you rather pixel perfect texture mapping.
明显是纹理重采样问题。您的 iPhone 可能正在将纹理重新采样为新尺寸 n^2。例如 512x512。仅使用维度为 2 的幂的纹理,因为这是大多数图形硬件所要求的。
blatantly a texture resampling issue. Your iphone is probably resampling the texture to a new size, n^2. 512x512 for example. Only ever use textures that are powers of 2 in dimensions as this is required by most graphics hardware.