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 开发者_StackOverflow中文版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.pngThe 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.
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.
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.
精彩评论