I always heard dreams form from things you've thought about during the day.
I.E: If you spend all day thinking about, for example, a new game you want - you might dream about it. This might also be, ehem, why teenagers tend to dream about sex quite alot - because it's always on their mind.