I'm trying to map a texture onto a hexagon, but I can't figure out the texture coordinates.
These are my vertices:
private float vertices[] = { 0.0f, 0.0f, 0.0f, //center
0.0f, 1.0f, 0.0f, // top
-1.0f, 0.5f, 0.0f, // left top
-1.0f, -0.5f, 0.0f, // left bottom
0.0f, -1.0f, 0.0f, // bottom
1.0f, -0.5f, 0.0f, // right bottom
1.0f, 0.5f, 0.0f}; // right top
The hexagon's "base" is vertical. (Mainly because I couldn't be bothered to figure out how to rotate the damn thing XD) Now the thing is, I have no idea how to figure out the texture coordinates. I've looked all over the web, but still wasn't succesful.
I'd really appreciate if someone could explain to me how to figure out texture coordinates, because apart from texturing a simple square I just cannot figure it out I'm afraid.
Note: It's a "square" hexagon, so not based on a circle. EDIT: The hexagon is drawn using LG_TRIANGLE_STRIP.
PROBLEM SOLVED. I now understand how to figure out these coordinates. Here are the ones that worked for me:
private float texture[] = { 0.5f, 0.5f,
0.5f, 0.0f,
0.0f, 0.25f,
0.0f, 0.75f,
0.5f, 1.0f,
1.0f, 0.75f,
1.0f, 0.25f };
Texture coordinates work almost like percentages from 0.0 to 1.0 where (0.0, 0.0) is in the lower left. If your texture image is 128 x 128 pixels, then the point (0.25, 0.25) would be 32 pixels in from the left and bottom. Working with what you had there, if you were trying to have the hexagon inscribed exactly inside a square texture graphic, your coordinates should look something like this:
private float textureCoords = { 0.5f, 0.5f,
0.5f, 0.0f,
0.0f, 0.25f,
0.0f, 0.75f,
0.5f, 0.0f,
1.0f, 0.75f,
1.0f, 0.25f };
If I recall correctly, you also want the image flipped vertically.