You are my sunshine, my only sunshine. Well, that's where a huge source of thermal energy comes from. So in that sense thermal energy is mainly used for heating the earth. Thermal energy comes from the movement of molecules and atoms in matter. You can find more information here: http://thermalenergy.org/