Texture Coordinates
  • Specify a texture coordinate at each vertex (s, t) or (u, v)
  • Canonical coordinates where u and v are between 0 and 1
  • Simple modifications to triangle rasterizer

public void Draw(Raster raster) {
    .
    .
    .
    PlaneEqn(uPlane, u0, u1, u2);
    PlaneEqn(vPlane, v0, v1, v2);
    .
    .
    .
    for (y = yMin; y <= yMax; y += raster.width) {
        e0 = t0;  e1 = t1;  e2 = t2;
        u = tu;   v = tv;   z = tz;
        boolean beenInside = false;
        for (x = xMin; x <= xMax; x++) {
             if ((e0 >= 0) && (e1 >= 0) && (e2 >= 0)) {
                 int iz = (int) z;
                 if (iz <= raster.zbuff[y+x]) {
                     int uval = u * texture.width;
                     uval = tile(uval, texture.width); 
                     int vval = v  * texture.height;
                     vval = tile(vval, texture.height);
                     int pix = texture.getPixel(uval, vval);
                     if ((pix & 0xff000000) != 0) {
                         raster.pixel[y+x] = pix;
                         raster.zbuff[y+x] = iz;
                     }
                 }
                 beenInside = true;
    	     } else if (beenInside) break;
    	     e0 += A0;   e1 += A1;   e2 += A2;
    	     z += Az;    u += Au;    v += Av;
    	}
    	t0 += B0;   t1 += B1;   t2 += B2;
    	tz += Bz;   tu += Bu;   tv += Bv;
    }
}
	
Lecture 21 Slide 4 6.837 Fall '98