Others have said this, but D&D doesn't have much in the way of lore. It is a system for playing a game in any setting, and it is the setting that has lore. So if you are playing D&D in a Tolkien setting you have Tolkien lore, D&D in a Warhammer setting would use Warhammer lore, D&D in the Planescape setting would use Planescape lore, and so on.
You mentioned Total War: Warhammer, and that's an excellent example to explain the concept. "Total War" is a series of games that provides a system for playing out a war in a given setting. Many of the Total war games are set in the real world, such as Rome: Total War or Total War: Attila. Total War: Warhammer is set in the Warhammer world, and so would use lore from that setting instead of the real world. So "Total War", like "D&D", is the system; and "Warhammer" is the setting.
Typically when people play D&D they develop their own world with its own history that's different from that of any other D&D group. There are quite a few published settings though - the closest to being a "default" setting is the World of Greyhawk (although that doesn't get much attention these days). That's sort of like an early Middle Ages Europe with many kingdoms frequently going to war over territory, but all purely fictional instead of drawn directly from the real world, and with plenty of fantasy elements such as magic, elves and gods that actually do intervene in the affairs of mortals.
Another setting is Dragonlance, which is one of those typical homebrew game worlds that grew organically around one D&D group's game. This particular group happened to contain several skilled authors who wrote a series of stories about what happened in their game. The stories were popular and a published setting based on the stories was developed. The idea is that all the gods and dragons of the world had long ago decided to separate themselves from the world of mortals, but one of them isn't happy with that arrangement so she sent all the dragons loyal to her to go and conquer everything. Eventually the other dragons arrive to help the defenders try to push the invaders back, and you end up with a sort of World War III scenario, but with knights riding on dragons.
Forgotten Realms is a slightly non-standard but well-known setting, popularised by numerous fiction authors who use the setting as a shared universe, as well as a string of high-profile games from Bioware. Part of the appeal of this setting is the shared-world aspect and strong tie-in with a very large body of fiction from many popular authors, which means that players regularly encounter and interact with some of the numerous famous heroes and villains that they may have read or heard about from books or computer games. Some of the most famous characters are Drizzt Do'Urden, a renegade drow (a race of cruel "dark elves" who live deep underground) who went on to become a renowned hero to surface-dwellers; and Elminster Aumar, a prominent wizard and something of a mascot for the setting.
There's Planescape, a setting that focuses on travelling between different realities. The idea is that there are hidden gateways between worlds, mainly to and from a enormous city (and self-contained world in its own right) called Sigil. There's the Ravenloft setting, which provides for spooky ghost-story games where everywhere you go is beset by some sort of horror. There's Dark Sun, which is about a post-apocalyptic desert world.
So, lots of different settings, each with their own lore.