This site has some example

http://wiki.vrmedia.it/index.php?title=Shadow_Mapping

The C++ code

```
glMatrixMode(GL_TEXTURE);
glLoadIdentity(); // clear things up
glTranslate(0.5, 0.5, 0.5); // we have to clamp values in the [0.0, 1.0] range, not [-1.0, 1.0]
glScale(0.5, 0.5, 0.5);
glMultMatrix(light_mat_proj); // now multiply by the matrices we have retrieved before
glMultMatrix(light_mat_modelview);
// finally, multiply by the *inverse* of the *current* modelview matrix
var s_mat_m = glGet(GL_MODELVIEW_MATRIX);
if (! InvertMatrix(&s_mat_m))
Quit("Singular view matrix!"); // this should not happen
glMultMatrix(s_mat_m);
glMatrixMode(GL_MODELVIEW);
```

and the VS shader

```
[VERTEX SHADER]
varying vec4 shadowTexCoord;
void main (void)
{
// vertex calculation
gl_Position = ftransform();
// shadow texture coordinates generation
shadowTexCoord = gl_TextureMatrix[0] * gl_ModelViewMatrix * gl_Vertex;
}
```

Why are they computing InvertMatrix(&s_mat_m)

and then in the shader

shadowTexCoord = gl_TextureMatrix[0] * gl_ModelViewMatrix * gl_Vertex;

Isn’t it simpler to not apply the inverse in the C++ and in the shader

shadowTexCoord = gl_TextureMatrix[0] * gl_Vertex;