Cooling trapped atoms in optical resonators