Genetics of ecological divergence during speciation