The transformed vertex due to the model*view*projection transformation ends up in clip space. To translate that into ndc, you need to take into account the perspective divide as such:
// vertex shader: float4 p = mul(mvp, vertex); o.screenPos = p; // fragment shader: float2 screenPos = (i.screenPos.xy / i.screenPos.w) * 0.5 + 0.5;
You ignore the z coord.
screenPos will be in 0..1 range. Is this what you need?
gluPerspectiveA(90.0, 2.0, 10.0, 1000.0 * 1000.0);
This doesn't look right to me. You are passing a near plane of 10 (which means you will get shadow clipping when the camera is very close), and a far plane of 1000000. Also, why is aspect ratio = 2?
I'd suggest to go with an orthographic projection to begin with instead of sharing the same projection matrix between your main camera and your light shadow caster.