I was quite frustrated before I made shadow mapping work. I used a demo from OpenGL Distilled book as a template, where the depth map is used as a second texture, while the first unit is regular color texture. The problem why I lost almost 2 days to make things right is that I didn’t re-set the eye planes for the second texture unit upon each repaint. And my wonder is why this is neccessary anyway. I configure both texture units in the initialization code like this:
I load the first texture from file, and I calculate the second (i.e. the shadow map), by drawing the scene from light view, copying the depth buffer to texture, and then setting ;
glTexGenfv( GL_S, GL_EYE_PLANE, &(lightMatrix) );
where lightMatrix is a concat of four matrices (but those who did shadow mapping must know what I am talking about).
All of the above functions change the active texture unit’s state which should remain unchanged when the texture units are switched. For some reason, however, I have to set the eye planes (as in the above line) on each repaint, even if I changed nothing else about the shadow map or second texture unit meanwhile. As if the switch to the other texture unit (which I must do because I have two textures bound to it) would reset the eye planes.
Can someone please clarify this OpenGL behavior and tell me if something else about the texture state changes in the same manner?
In the end, and this could be quite mathematical, what is the difference between using the light-view matrix to set the texture eye planes (which supposedly transform the texture coordinates into light-space) and setting the texture transformation matrix directly? Wouldn’t the latter transform in the same way? Or is it something about coordinate interpolation?