You're going to have to check the laws of your own state, county, and municipality (if any). There are no country-wide rules. Best would be to ask a lawyer for specific advice.
I am not a lawyer. Do not rely upon my opinions.
That said, now here are my opinions:
Usually, a legal shooting would probably have to be the result of a credible threat against your life, or that of another person, by someone of superior force and ability. The basic requirement is a physical (rather than merely verbal) attack, including either a deadly weapon or decidedly superior strength.
It is generally best to avoid any hint of brandishing your firearm. It should appear only as the response to a real, physical, deadly threat. There are exceptions, of course. If it ever happens that you must brandish, I strongly suggest that you should have a cell phone, and that you be the first to call 911 to report the incident.
Others may have better, or at least different, advice to offer.