Mary's parents were as distantly related as most mediæval marriages - if her dad had been Henry the Plowman instead of Henry the King, noone would have remarked on it - yet Mary was the only child who survived.
Anne, sister of Mary II, didn't marry her cousin yet also failed to reproduce.
Their father Jmaes II unrealated to Ann Hyde, similar.
Their uncle Charlie II, seventh cousin once removed (can you say distant) to Catherine of Braganza, no children
Forward to the Hanovarians: George I married his first cousin, 2 children in first 5 years of marraige (before irreconcilable differences set in). His descendents were remarkably prolific, including Victoria, who also married her first cousin.
Conclusion: Fertile people have fertile children: Infertile people have infertile children.
James II had a number of children by his first wife who died young besides the two daughters who survived. Anne had at least 17 children including stillborn babies and children who died shortly after birth--one son lived to the age of 11, the rest died at 2 or younger.
Catherine of Braganza was a descendant of one of the illegitimate children of Pope Alexander VI (the Borgia pope). So if she had produced a son, England would have had a king descended from a pope (and also descended from St. Francis Borgia, an early Jesuit, who entered the Jesuit order after becoming a widower). And there might not have been a "Glorious Revolution."