Page 111 - Computer Graphics Handout
P. 111
the first index of the first vertex specified by quad to fix the color for the entire face.
Here are the RGBA colors,
color4 colors[8] = {color4(0.0,0.0,0.0,1.0),
color4(1.0,0.0,0.0,1.0),
color4(1.0,1.0,0.0,1.0),
color4(0.0,1.0,0.0,1.0),
color4(0.0,0.0,1.0,1.0),
color4(1.0,0.0,1.0,1.0),
color4(0.0,1.0,1.0,1.0),
color4(1.0,1.0,1.0,1.0)};
and the vertices of a cube that corresponds to the clipping area in clip coordinates,
point4 vertices[8] = {point4(-1.0,-1.0,1.0,1.0), point4(-1.0,1.0,1.0,1.0),
point4(1.0,1.0,1.0,1.0), point4(1.0,-1.0,1.0,1.0),
point4(-1.0,-1.0,-1.0,1.0), point4(-1.0,1.0,-1.0,1.0),
point4(1.0,1.0,-1.0,1.0), point4(1.0,-1.0,-1.0,1.0)};
Here is the quad function that uses the first three vertices to specify one triangle and the first, third, and fourth to specify the second:
int i = 0;
void quad(int a, int b, int c, int d)
{
quad_color[i] = colors[a];
points[i] = vertices[a];
i++;
quad_color[i] = colors[b];
points[i] = vertices[b];
i++;
quad_color[i] = colors[c];
points[i] = vertices[c];
i++;
quad_color[i] = colors[a];
points[i] = vertices[a];
i++;
quad_color[i] = colors[c];
points[i] = vertices[c];
i++;
quad_color[i] = colors[d];
points[i] = vertices[d];
i++;
}
Note the initialization of i outside the quad function. If, as in later examples, we invoke quad multiple times, either because we
change the colors or locations of the same vertices or we have multiple cubes, we must be careful as to where we start placing data
in the points array. Our program is almost complete, but first we examine how the colors and other vertex attributes can be assigned
to fragments by the rasterizer.
111

