Skip to main content
GameDev.net gamedev.net
🔒 Locked

Textures on Triangles

Started by C plus noob Aug 18, 2005 at 9:16 PM 8 replies 1.3k views
Original Post
C plus noob
C plus noob
i know how to map a texture onto a quad but how with triangles?
_the_phantom_
_the_phantom_
just the same way, you just give it three points instead of 4 and it takes a triangle shape out of the texture..
kburkhart84
kburkhart84
**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.


C plus noob
C plus noob
there has to be a better way...... i dont really care how its mapped as long as its on there
Sneftel
Sneftel
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"?
C plus noob
C plus noob
im not having a right triangle his way would map to a right triangle
Sneftel
Sneftel
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.
blizzard999
blizzard999
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.
KyRo1989
KyRo1989
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.
kburkhart84
kburkhart84
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.


Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.