Jump to content
  • Advertisement
Sign in to follow this  
C plus noob

Textures on Triangles

This topic is 4839 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

Advertisement
**EDIT** Phantom beat me, oh well **END EDIT**

One of NEHE's tuts shows you, but I'll tell you to make it quicker. In reality, it is the same way as with a quad, only using three verts. For example, this will draw the triangle, using the upperleft, lowerright, and upperright of the texture.


glBegin(GL_TRIANGLES);
glTexCoord(0, 1);//UV for upper left
glVertex3f(-1, 1, -5);
glTexCoord(1, 0);//UV for lower right
glVertex3f(1, -1, -5);
glTexCoord(1, 1);//UV for upper right
glVertex3f(1, 1, -5);
glEnd();


This is assuming you have texturing enabled and the texture binded. It would look like the upper left half of the quad, but cut in half corner to corner.

Like This.

*****
* *
* *
**
*


It would have that portion of the texture as well.

Share this post


Link to post
Share on other sites
Quote:
Original post by C plus noob
there has to be a better way...... i dont really care how its mapped as long as its on there

What do you mean "a better way"? What do you perceive as the problems with "this way"?

Share this post


Link to post
Share on other sites
Only because that's the coordinates he used. Other sets of vertex coordinates would produce a different triangle, and other texture coordinates would change how the texture was mapped onto the triangle.

Share this post


Link to post
Share on other sites
The example proposed by kburkhart84 is the right one with those coordinates. Sure.
Remember also that with the texture matrix, in the same way as the modelview, you can rotate, translate and scale your texture coordinates.

Share this post


Link to post
Share on other sites
I'm not really sure what you want, but I made a demo which may be useful for you:
Link
the demo shows a way how to calculate the texture coordinates to make the texture always standing like on a right triangle. Use t to toggle between precalculated texturemapping and the realtime calculation. The Source is commentated too.

edit: note that this calculation can get slow when using a huge amount of dynamic triangles.

Share this post


Link to post
Share on other sites
My example should show you how to do it. I think it's up to you to calculate what the actual verts and UV coords are. It depends on the triangle. You can do any coords with any verts just like with quads. You don't have to use the whole texture. Triangles are the same way except that it is only 3 instead of 4 verts. The texture that is between the 3 UV coords you give it will be used and put inbetween the 3 verts you draw.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!