PDA

View Full Version : Is there another way to put a texture on a pentagon?

01-12-2003, 04:15 AM
Hello,
i would like to know if it is possible that my picture is put in one piece on the pentagon and not in 5 pieces as is now.
Would be nice if someone could help me.
Here is my code:

void Tpentagon(float laenge) {
glBegin(GL_POLYGON);
glTexCoord2f(2.5,2.5);
glVertex2f(2.5,2.5);
glTexCoord2f(1,1.5);
glVertex2f(1, 1.5);
glTexCoord2f(2,0.5);
glVertex2f(2, 0.5);
glTexCoord2f(3,0.5);
glVertex2f(3, 0.5);
glTexCoord2f(4,1.5);
glVertex2f(4, 1.5);
glEnd();
}

Bob
01-12-2003, 04:48 AM
Adjust the texture coordinates so they map the texture only once onto the polygon.

For example, the vertex with largest X-coordinate get S-coordinate (the texture's X-axis) 1, and the vertex with smallest X-coordinate get S-coordinate 0. Same for the Y- and T-axis.

glTexCoord2f(0.5, 1);
glVertex2f(2.5, 2.5);
glTexCoord2f(0, 0.5);
glVertex2f(1, 1.5);
glTexCoord2f(0.33, 0);
glVertex2f(2, 0.5);
glTexCoord2f(0.66, 0);
glVertex2f(3, 0.5);
glTexCoord2f(1, 0.5);
glVertex2f(4, 1.5);

4 is the largest value along the X-axis, and has the texture coordinate 1. 1 is the smallest, and get the texture coordinate 0. 2 is 1/3 between 1 and 4, and therefore get the texture coordinate 0.33. And so on...

01-12-2003, 06:47 AM
I would like to thank you, now it looks perfect and with your great description i was able to texture my hexagon accordingly http://www.opengl.org/discussion_boards/ubb/smile.gif