I have a number of 2D polygons which I am drawing using OpenGL ES 2.0 with GLKit. Using these vertices, I have used Quartz2d to draw a UIImage which matches each shape to use as a texture.
What I now want to do is calculate the correct texture UV coordinates for each shape. Is there any easy way to do this ?
Many thanks.
Maybe I didn't understand correctly, but if you have 2D shape with image mapped onto it as texture then texture coordinates lie in range from 0 to 1 for corresponding vertex coordinates from 0 to image size.
So,
tex.x = vertex.x / imageSize.width
,tex.y = vertex.y / imageSize.height
.PS: may be
tex.y = 1.0f - vertex.y / imageSize.height
if image is rendered flipped vertically.