So after Neo takes the red pill, he is faced with the "real world", which is a dystopian future controlled by machines, with only remnants of humankind left. I've always been puzzled by how it got to be this way in the "real world". Is there any canon source that states what happened? Was the real world just like the Matrix until humans created the machines? How was the real world like before dystopian Zion and how did the machines come to be created, and how did they eventually take over?
This story is told in The Animatrix, specifically, "The Second Renaissance". It's a recounting of the events leading to machine uprising, beginning with creation of the fist AI. It's basically expansion on the story Morpheus told Neo, with way more details and an added visual part.
Here's a summary:
In the mid-21st century, humans develop AI. One robot overheard its owner planning for it to be scrapped, and it killed him to prevent this. It was tried and found guilty of murder and sentenced to be destroyed. The rest of AI was sentenced to death as well. Protests and violence, followed by all intelligent robots founding their own city-state called 01. Due to its incredible technological advantage, 01 gained a lot of international manufacturing power. 01 asked to be admitted to the UN. It was denied, and the world decided to destroy it by attacking with nuclear weapons. 01 retaliated and quickly conquered territory. Humanity reacted by blocking out the sun, thinking that the machines only ran on solar power, but the machines were able to adapt.
TL;DR: Humans started to kill machines, a war broke out, humanity lost.
In the short "The Second Renaissance" in "The Animatrix" it is shown that the machines created a nation called '01', and
at first the machines attempted peaceful cooperation
But that failed and led to
The humans and machines fought a war
(when humanity blackened the skies in an attempt to cut the machines from the solar power they used) and humanity lost.
Then the machines
in a UN session demanded that the humans surrender their bodies, or face extinction.
And this is how
People was hooked into the Matrix, to serve as a power source for the machines.