   Shadow Mapping Woes
  http://www.paulsprojects.net/tutorials/smt/smt.htmlhttp://dalab.se.sjtu.edu.cn/~jietan/shadowMappingTutorial.htmlThey both put the depth texture into texture unit 0, enable automatic UV generation for that unit, etc., then go on to render the scene.Pseudo-code in Pass 3:matrix44 textureMatrix = biasMatrix * shadowLightProjectionMatrix * shadowLightViewMatrix;    textureMatrix.transpose();    //Set up texture coordinate generation.    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);    glTexGenfv(GL_S, GL_EYE_PLANE, textureMatrix[0]);    glEnable(GL_TEXTURE_GEN_S);  glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);    glTexGenfv(GL_T, GL_EYE_PLANE, textureMatrix[1]);    glEnable(GL_TEXTURE_GEN_T);   glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);    glTexGenfv(GL_R, GL_EYE_PLANE, textureMatrix[2]);    glEnable(GL_TEXTURE_GEN_R);glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);    glTexGenfv(GL_Q, GL_EYE_PLANE, textureMatrix[3]);    glEnable(GL_TEXTURE_GEN_Q);glEnable(GL_TEXTURE_2D);    ////Bind & enable shadow map texture    glBindTexture(GL_TEXTURE_2D, shadowMapTexture);    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);    //Shadow comparison should be true (ie not in shadow) if r<=texture    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);    //Shadow comparison should generate an INTENSITY result    glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);    //Set alpha test to discard false comparisons    glAlphaFunc(GL_GEQUAL, 0.99f);    glEnable(GL_ALPHA_TEST);    setupNormalLight();    DrawScene();    ...I think the question(s) this begs should be pretty obvious:#1: But, uh, I have textures on my models, and they are going into texture unit 0 as they should be (this is quite standard).  So won't the depth texture get removed from unit 0 once I set one of my model textures to unit 0?And all those calls to glTexParameteri() are going to affect my model textures in unit 0.#2: So if the depth texture and my model textures are going to clash, what happens if I set the depth texture to a unit other than 0?  Particularly the last unit.  It is going to process all the texture units in order from 0 to X.  By the time it gets to X, hasn't it already done the depth compare?  So it is too late to perform a depth compare using the depth texture.  Isn't it?L. Spiro   
  use multitexture, theres no doubt tutorials at the links youve suppliedegglActiveTexture( GL_TEXTURE1 );bind depthglActiveTexture( GL_TEXTURE0 );bind color texture   ;  So that answers my #2.So you can set the depth texture into any unit and it will still work.But may I ask for a bit more detail as to what will happen under the scenes?I know how multi-texturing works (generally) and how the texture units are processed, so my question is not about that.I mean the depth comparison comes from the texture, which is in a texture unit.When that unit is 0, as is always shown in tutorials, there is no question as to what is happening.  But if I move it to any other unit, how does the depth comparison get picked up?  If it processes all the texture units in order, it would get all the colors and compile the fragment up to the Nth texture unit (where the depth texture would be), and then upon reaching the depth texture it would finally do the (delayed) depth comparison, and then throw everything away and move on (upon failure)?This would cause a performance loss I imagine.Or does setting depth comparison on any unit automatically make OpenGL jump directly to that comparison in place of its default depth comparison?Last question.I thought my book—Beginning OpenGL Game Programming, By Dave Astle and Kevin Hawkins—mentioned this but from the small preview I could find online (I left the actual book at home) I could not find it.  The texture units do not have to be contiguous right?  As long as a texture unit is not set up to reference a texture unit that is not active.  I should be able to set my regular textures in the first X available slots, and always put the depth texture in the last slot, even if slots 1 and 2 have not been enabled.Thank you,L. Spiro   