We introduce a polymer model where the transition from swollen to compact configurations is due to interactions between the monomers and the solvent. These interactions are the origin of the effective attractive interactions between hydrophobic amminoacids in proteins. We find that in the low and high temperature phases polymers are swollen, and there is an intermediate phase where the most favorable configurations are compact. We argue that such a model captures in a single framework both the cold and the warm denaturation experimentally detected for proteins. Some consequences for protein folding are discussed.