#### Archived

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

# how does texture mapping work?

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

## Recommended Posts

ok so you got these triangles and you got this rectangular texture ok so the texture goes on the triangle the square texture goes on the triangle the square, the triangle

##### Share on other sites
it''s easy (if you''re good at math anyway). think of each vertex as having texture coordinates U,V (which are just the x and y coords of texture).
now when you project the triangle (you can use any shape really but they are they easiest) you just interpolate the U,V coords between the verticies on the screen. make any sense?

think of it like this, i''ll show a line for easy understanding. say you have a texture that is 10 texels (texture pixels) wide and you have a line that is 20 pixels long on the screen.

the line on screen:
--------------------
and the texture:
-+-+-+-+-+

you wanna stretch the texels out to fit the line..
--------------------
--++--++--++--++--++

ok so far? so to do this you''d take the texture width (for now for easyness) and divide it by the run of the line which will give you 0.5 (10/20=0.5). now all that number is is the amount of texels you increment per screen pixel. kinda get it? so starting out with 0, then .5,1,1.5,...., and all the way till 10 as the last pixel. the middle of the line being the 5th texel.

that describes the theory behind affine texture mapping, not perspective correct where you take Z into account. hope this helps, it''s might not be enough to write your own texture mapper but it should make you understand the basics and help you on your way to understanding much easier.

##### Share on other sites
er whoops, the pixel line length and texture size (the second "diagram") were supposed to be equal in length. otherwise it makes no sense

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 18
• 20
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633363
• Total Posts
3011514
• ### Who's Online (See full list)

There are no registered users currently online

×