About OpenGL Functions Used in This Tutorial

As noted from the Discussion page, we produce the shadow on a plane by applying a transformation to the geometry that casts the shadow. Further, the Discussion page describes how to construct the 4x4 matrix that performs the transformation. We discuss here how to use OpenGL so as to apply the transformation.

First, suppose we use the following two-dimensional array for storing our 4x4 projection matrix.

double projection[4][4];
Since the current matrix on top of the model-view stack is applied to the geometry, we only have to combine through matrix multiplication our projection matrix with the current model-view matrix. This is accomplished with the following function.
glMultMatrixd(const GLdouble *m)
where m is an array of 16 values holding the entries of our projection matrix. Further, the entries of our projection matrix must be stored in m column by column -- that is, the four entries of the first column are stored first, then the entries of the second column, etc. The following declaration of m and nested iteration achieves our goal of storing in m the entries of projection.
double m[16];

for (int j=0; j<4; j++)
    for (int i=0; i<4; i++)
        m[i+4*j] = projection[i][j];

Of course, when we call glMultMatrixd, the model-view stack must be the current one. Also, since we want m present only when the shadow casting geometry is drawn, we need to make calls to the usual push and pop functions. Last, the shadow is drawn as a simple color and, in turn, we have to disable lighting. The following code snippet carries out the tasks with a teapot as the geometry.

glDisable(GL_LIGHTING);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glMultMatrixd(m);

glColor4fv(shadowColor);
glutSolidTeapot(1.0);

glPopMatrix();
If we need to scale, rotate or tranlate the teapot so as to fit into our world, then the necessary gl calls for carrying out the transformations are made after the call to glMultMatrixd and before the call to glutSolidTeapot.