This X-ray image of the sun gives some hint of the remarkable energy it generates and releases.
The sun is not a very pleasant place to be. For example, the pressure at the bottom of the deepest ocean on Earth --- at the Mariana Trench --- would smash you into a messy glob, and the pressure at the center of the sun is 300 million times more. You wouldn't have to worry about it, though, because you'd be burned up as you would in a pot of molten steel --- except that the temperature is 10,000 times hotter. All that unpleasantness, though, leads to a cascade of events that results in the light that brings life to Earth.
In the Middle
Nearly all the mass of the entire solar system is concentrated in the sun.
The driving force that creates those high pressures and temperatures is gravity. The sun is so massive --- 330,000 times as massive as the Earth --- that gravity pulls matter toward the center with incredible force. The force of gravity is balanced by the pressure of the hydrogen and helium that compose the sun. The pressure and temperature are so high that electrons are stripped away from the hydrogen and helium atoms, and the neutrons and protons at the core of the sun are free to crash into each other, unprotected by their electrons.
Fusion Energy
When a proton in the core crashes into another, most of the time it just bounces off. But in about a million years or so, the proton briefly turns into a neutron and crashes just at the right time to stick to a proton. Another proton joins in, then two of those resulting conglomerations crash into each other and stick and the hydrogen has been converted to helium. This action at the core releases energy, very high-energy gamma rays. Those gamma rays are like light; they would travel in straight lines if they could. The reason the Earth is not bathed in gamma rays is that they don't make it very far without bouncing into other particles in the dense solar core.
Moving Outward
The gamma rays push out from the center, bouncing from one nucleus to another. But as they get farther out from the core, the temperature and pressure have decreased to the point where the electrons can still hang out around their nuclei. That is, the atoms can be whole again. About the place that happens, the atoms and nuclei that absorb gamma rays find it easier to get rid of that extra energy by bouncing around and crashing into other neighboring atoms. So those atoms start swirling around like hot air above a desert, churning in big loops that drive toward the surface of the sun and back down. They also emit light --- this time visible light, but again, the light is still too far under the surface to make it out.
The Photosphere
Although energy is being radiated by particles all throughout the sun, the light that makes it out comes from only the top 100 or 200 kilometers.
Finally, the energy created at the core of the sun has made its long journey to within a couple hundred kilometers of the surface. The temperature is now all the way down to about 10,000 degrees Fahrenheit. The light from lower levels gets absorbed here. The energy in the atoms in this layer gets emitted as visible light. Because the energy is spread among atoms at different temperatures, there's a spread of the spectrum of light from the sun. The top couple hundred kilometers that emit the light we see are called the photosphere.