Archived

This topic is now archived and is closed to further replies.

dadio

texures on a triangle strip

Recommended Posts

dadio    122
Hi there... Ho do I pass coordinates of texure to a triangle strip which I draw in a loop. Every loop, I draw only two new points (vertics), but I need 4 to texure map my image... Good solution, anyone? thx

Share this post


Link to post
Share on other sites
didilabu2    122
If you wanted to stretch the texture across the entire strip you can do this:

float NUMCOLS = (however many);

...

glBegin(GL_TRIANGLE_STRIP);
for (float c = 0; c < NUMCOLS; c++) {
glTexCoord2f(c/NUMCOLS, 0.0f);
glVertex3f(...);
glTexCoord2f(c/NUMCOLS, 1.0f);
glVertex3f(...);
}
glEnd();

So at the beginning of the strip, c = 0, so c/NUMCOLS = 0.0 (the left edge of the texture).
At the end of the strip, c = NUMCOLS, so c/NUMCOLS = 1.0 (the right edge of the texture).
Everything else in between is a fraction between 0 and 1.



----------------------------------------------------------------



If you want to tile the texture you could do this:

...

glBegin(GL_TRIANGLE_STRIP);
for (int c = 0; c < NUMCOLS; c++) {
int u = (c % 2);
glTexCoord2i(u, 0);
glVertex3f(...);
glTexCoord2i(u, 1);
glVertex3f(...);
}
glEnd();


% returns the remainder.
So, every time c is even, c % 2 = 0 (left edge of texture).
Every time c is odd, c % 2 = 1 (right edge of texture).

Share this post


Link to post
Share on other sites