In an A-to-Z edition of State of the Arts: Fantasia and Fugue. Both allow the performer (and composer) to show off their skills, but in a different way. A fantasia tends to be virtuosic, but at the same time should sound like it’s being improvised. A fugue, in order for it to work, has to also meet certain formal expectations. Especially important: the opening subject needs to be one that the listener will be able to recognize each time it enters, in ever thickening textures of other voices. Counter-subjects need to flow out of what precedes them, and be able to follow the rules of harmony and counterpoint when played at the same time as the subject. It all needs to make sense both structurally, and just as importantly, to the ear.
How one writes a fugue really depends on the starting material; there are going to be some techniques that will only be possible if the subject allows it. Bach was especially talented at knowing what permutations would be possible based on any given theme: with a fugue for three voices, he might have two counter-subjects, each showing up in a different part in turn. And then for the final statement, they might each come in earlier, ending up overlapping to build tension.
Here’s a quartet of singers (plus a string quartet) performing Glenn Gould’s “So You Want to Write a Fugue”: