Simply put, changes in price come about through the laws of supply and demand. If there are more buyers than sellers at a particular price then the price will rise to discourage buyers and encourage sellers until equilibrium is restored. Conversely if there are more sellers than buyers then the price will fall to encourage more buyers and discourage sellers.
The mechanism for the markets, however, is different for stocks and futures. All stocks have an assigned market maker whose job it is to make a market in that particular share, they must quote a bid and an ask price. They make their money on the spread.
Futures do not have a defined market maker and prices are matched between individual participants in the market.
Generally futures continue to trade electronically out of normal market hours, matching up buyers and sellers albeit with a much reduced liquidity. For example the e-mini s&p 500 contract trades from 16.45 to 16.10 (US time), ie 23 1/2 hours a day! Futures can move a long way out of normal trading hours leading to what appears to be an opening gap when normal trading hours start.
If the futures trading indicates a strong move in the market out of hours or there is specific news relating to a company, then the market makers in stocks will post their opening prices accordingly, leading to a gap open.