Yes, we've done it before with varying levels of success. You can mask off the areas or you can use a liquid mask and spray it on, then use an exacto knife to remove the to-be painted areas. Last time I did that approach, the liquid mask, had some issues with mask delaminating as it dried. But I have done it, just need the right stuff. Maybe someone can share the liquid mask they've used successfully.
You also want to make sure the glass is clean from contaminates before painting. As the adhesion between paint and glass is not great to begin with. One of the ones we did years ago, the paint came off years later, but it hasnt happened since. I think the last time we did it we just used urethane paint.
This is the stuff I used last time as a mask, but like I said it had a tendency to delaminate in some areas as it dried. There must be better stuff out there.
https://www.amazon.com/gp/product/B00063VVM2/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1