Display turns black after a few seconds at the login screen before logging in When I boot into Windows via Boot Camp, everything works fine.

When I boot into safe mode by holding down shift on boot up, everything works fine. 

When I boot with an external monitor hooked up, everything works fine (both the laptop screen and the external monitor work). If I unplug the external monitor, it stops working, and re-plugging in the external monitor doesn't help.

Originally I was running OSX El Capitan. I just upgraded to Sierra. Still doesn't work.

I've already attempted resetting the SMC and PRAM/NVRAM.

I've very quickly clicked on a user account before the login screen goes black, no dice there either.

I had been using a program called f.lux to make my screen dark at night. I went ahead and took it off of the startup programs for my user account, and deleted the color display profile corresponding to it. Perhaps it could still be messing with things even though it's not on my user's start up programs anymore.

This happened to me about a week ago. I reset the SMC back then too, and at that time, it seemed to fix it. But now it's back.

Also, one time only, my login screen was duplicated a bunch of times and had some distortion lines. It looked like this:



I spilled water on my computer forever ago and took it somewhere to get fixed. I guess this could partially be a hardware problem, but if so, it is weird that it works in many circumstances.
Even though upgrading from El Capitan to Sierra didn't fix my problem, I reinstalled Sierra and now it works. I booted in recovery mode and reinstalled without an external monitor hooked up, if that matters.