Jump to content
  • Advertisement

Archived

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

dadio

texures on a triangle strip

This topic is 6196 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!