Affine Texture Mapping
by Andre LaMothe

Listing One
void Draw_Triangle(float x0,float y0,float x1,float y1,                                     float x2,float y2, int color)
{
// this function rasterizes a triangle with a flat bottom

// compute left side interpolant
float dx_left = (x2 - x0)/(y2 - y0);

// compute right side interpolant
float dx_right = (x1 - x0)/(y2 - y0);

// seed left and right hand interpolators
float x_left = x0;  
float x_right = x0;

// enter into rasterization loop
for (int y=y0; y<=y1; y++)
     {
      // draw the scanline
      Draw_Line(x_left, x_right, y, color);     

     // advance interpolants
     x_left+=dx_left;
     x_right+=dx_right;

     } // end for y
} // end Draw_Triangle


Listing Two 
// initialize u,v interpolants to left and right side values
ui = ul;
vi = vl;

// now interpolate from left to right, i.e, in a positive x direction
for (x = xstart; x <= xend; x++)
     {
      // get texture pixel value
      pixel = texture_map[ui][vi];

      // plot pixel at x,y
      Plot_Pixel(x,y,pixel);

      // advance u,v interpolants
      ui+=du; 
      vi+=dv;
      } // end for x



1


