The short answer
It depends on the country. Many passport offices now prefer photos without glasses because of glare and shadows. Some countries allow glasses only if both eyes are clearly visible with no reflections.
If you must wear them
Use frames that do not cover your eyes, tilt the camera slightly so lights do not reflect, and take several shots to find one with no glare. Some offices ask for a signed statement for medical reasons.
Easier option
Take your glasses off for the photo and put them back on after. It avoids the most common cause of rejection.
Hats and head coverings
Hats are normally not allowed. Head coverings worn for religious or medical reasons are usually allowed as long as the full face from chin to forehead is visible and there are no shadows.
Make your photo
Use the passport photo maker to crop to your country's size, then check the official rules before submitting.