I'm attempting to draw a rectangle with modern Opengl using a shader to do fill and stroke. I'm sending the fill color, stroke color and stroke width to a uniform block in the fragment shader (along with rectangle position and size). What is the recommended way for setting the stroke fragments to the stroke color and the fill fragments to the fill color?
At the moment, I have 2 ideas floating in my head. First, an if statement that checks whether the frag coordinate is within the bounds of the rectangle or rectangle stroke and set the frag color based on that. This methods would produce quite a large a complex if statement and when it comes time to rotate the rectangle, it may get even worse. (Also, I've read that branching in a shader should be avoided)
The second idea I have is to use a signed distance function to determine the color, but I am unfamiliar with using these and I have this idea that they don't do sharp corners too well.
Am I way off the mark here? Is there perhaps a better way to do this?