Advertisement

texures on a triangle strip

Started by August 01, 2001 08:03 AM
1 comment, last by dadio 23 years, 6 months ago
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
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).
Advertisement
thx

This topic is closed to new replies.

Advertisement