If you don't mind getting a little more complicated, there's a CSM tutorial on my website here. More specifically, it's how to adapt the shadowmapping.c code Superku pointed you to into Cascaded Shadow Mapping, which is relatively easy but effective over huge distances.

Jibb


Formerly known as JulzMighty.
I made KarBOOM!