The common way to obtain energies from Kohn-Sham exchange potentials is by using the Levy-Perdew virial relation. For potentials that are not functional derivatives (i.e., nearly all model exchange potentials in existence), this approach leads to energy expressions that lack translational and rotational invariance. We propose a method for constructing potential-based energy functionals that are free from these artifacts. It relies on the same line-integration technique that gives rise to the Levy-Perdew relation, but uses density scaling instead of coordinate scaling. The method is applicable to any exchange or correlation potential that depends on the density explicitly, and correctly recovers the parent energy functional from a functional derivative. To illustrate our approach we develop a properly invariant generalized gradient approximation for exchange starting from the model potential of van Leeuwen and Baerends.