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

Texturing TRIANGLES

Started by MeeZ Nov 23, 2003 at 9:02 PM 1 replies 750+ views
Original Post
MeeZ
MeeZ
Hey there, I have recently made up what looks like a ''mace'' (a sphere with spikes in the form of triangles). anyway, I have a texture mapped onto my quadric (the sphere) fine, but I don''t know how to map to a triangle. I understand the for points needed to specify for a quad, (0,0) (1,0) (0,1) and (1,1). How do i do this for a triangle. Sorry if this is an easy question. But it is just bugging me because I can''t texture a bloody simple triangle!!! Hope you can help me out. Thanks for your time. Cheers, MeeZ
MeeZ
styles_b
styles_b
The easiest thing to do is just find a convention for drawing your squares and stick w/ it. For example, I render all my polygons in clockwise order, so to draw my square as triangles I use a triangle fan function then send the points (0, 0), (0, 1), (1, 1), (1, 0) and your tex. coordinates should recipricate that. If you aren''t using a triangle fan drawing your square using triangles will be a little slower then simply drawing the quad. Check out nehe for more on texture mapping.
BriW111
BriW111
When u do texturing on quads, here is what u usually do:

glTexCoord2f(0.0f, 1.0f);
glVertex3f(-1, 1, 0);

// Display the bottom left vertice
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1, -1, 0);

// Display the bottom right vertice
glTexCoord2f(1.0f, 0.0f);
glVertex3f(1, -1, 0);

// Display the top right vertice
glTexCoord2f(1.0f, 1.0f);
glVertex3f(1, 1, 0);
(code taken directly from gametutorials.com's texturing demo)

ok, now here is how texturing works. given a texture (don't mind my bad diagram);
----------------------
|0,1-------------1,1 |
|--------------------|
|--------------------|
|0,0--------------1,0|
----------------------

those are the coordinates of the texture. now when texturing mapping a triangle, you can take just 3 of those points to make your texture, such as 0,0 1,1 and 1,0. you won't get the whole texture on your triangle, but that's the way you would do it. so:

glTexCoor2f(0.0f, 0.0f);
glVertex3f(1,0,0);
glTexCoor2f(1.0f, 1.0f);
glVertex3f(-1,1,0);
glTexCoor2f(1.0f, 0.0f);
glVertex3f(-1,0,0);

that's how you would texture a triangle



[edited by - BriW111 on November 25, 2003 10:26:58 AM]

Topic Locked

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

Sign in to reply to this topic.