i was trying to implement the shadow mapping technique but i have some problem in my code if anyone can help me .
here is a pseudo code :
//first pass from light postion
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(lightProjectionMatrix);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(lightViewMatrix);
glViewport(0, 0, W_shadow, H_shadow)
glCullFace(GL_FRONT);
DrawShadowedScene();
//get shadow texture
glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, shadow, shadow);
glCullFace(GL_BACK);
//second pass also from light position. reset view matrix
glClear( GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//bias for scaling for [-1 1] to [0 1]
Matrix textureMatrix=Bias*lightProjectionMatrix;
//texture generation for s,t,r,q using EYE_LINEAR ,the 4 plans //are the 4 lines of the texturematrix
//glTexGeni…glTexGenfv…glenable(GL_TEXTURE_GEN_…)
//draw the scene to generate s t r q
DrawShadowedScene();
//final pass : back to camera projection
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(cameraProjectionMatrix);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(cameraViewMatrix);
//shadow comparaison
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_ALPHA);
//draw with alpha test
glAlphaFunc(GL_GEQUAL, 0.99f);
glEnable(GL_ALPHA_TEST);
DrawShadowedScene();
//
i exlpain something for the second pass :
what i did in the second pass is that i reset the modeview matrix , so the texturematrix will contain only the lightprojectionmatix. and with eye linear texture generation the texturematrix will be post-multiplied with the inverse of the modelview matrix wich is an identity matrix . so the final texturematrix contain the light clip coordinate , and that ix excactly what i want to make texture comparaison . did i say something wrong. any idea why my method doesnt work ?