In some places, at certain times of the year, the sun is not a good source. Also dermatologists don't suggest using the sun to get vitamin D due to skin damage. Everything in moderation of course. I imagine the sun has other benefits than just vitamin d.
Also getting sun through glass does not give vitamin D.