Archived

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

how does texture mapping work?

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

Guest Anonymous Poster
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 this post


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

Share this post


Link to post
Share on other sites