Quite simply, the texture won't be distorted because you'll only be picking three texture coordinates - one per vertex. You'll have to use two triangles as outlined above, and "clip" different portions of the texture.
Pardon my horrible use of ASCII art here, and in the rest of this post:
Polygon Texture ADB ACD
A-----C | x-----x | x | x-----x
|\ | | | ___ | | | | ___ |
| \ | | |<o.o>| | |<o | .o>|
| \ | | | ### | | | ## | # |
| \ | | | -|- | | | -|- | |
| \| | | / \ | | | / \ | |
B-----D | x-----x | x-----x | x
You'd make two triangles - ADB and ACD. Point A maps to the top-left of the texture, B to the bottom-left, C to the top-right, and D to the bottom-right. If you only map one triangle or the other, you only get half of the sprite (or texture, for a more complex shape.) The same applies for larger or more complex polygons. The texture can be a single unified piece, but the texture coordinates of each vertex has to slice it up in the same manner as the geometry itself.
More complex example, a hexagon:
a b
___
/ \
f / . \ c
\ g /
\___/
e d
If you add a middle point of "G" and slice it up into six triangles (ABG, BCG, CDG, etc) you'll have to make sure that whatever texture you're using is sliced up coordinate-wise to match. This doesn't matter if you're just using GL_TRIANGLES
, since it's easiest to just leave the texture in its hexagonal shape, but once you start drawing strips or fans you can flip, skew, or duplicate if you don't keep close track of what vertex is mapping to what part of the texture, due to the drawing order.
As an aside, if you're just concerned with 2D screen-aligned quads - which is what sprites are generally for - use the OES_Draw_Texture extension available on the iPhone and save yourself a load of heartache while picking up a significant speed boost.
int rect[4] = {0, 0, 64, 64};
glBindTexture(GL_TEXTURE_2D, texMario);
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, rect);
glDrawTexiOES(playerX, playerY, spriteZ, width, height);
The rect
defines the coordinates of the texture you're going to snip out (in pixels, so this would be a 64x64 sprite) and then the actual call to glDrawTexiOES
plops it right into the screen view with its lower-left corner on playerX and playerY.
Goodness, even I get the feeling of "tl;dr" here. I apologize for that.