Selection favour males that anticipate intraspecific competition levels and develop appropriate competitive traits. In holometabolous insects, larval density can act as an ecological cue of males future intraspecific competition levels while also limiting access to food allocated to sexually selected traits (e.g., testes). To date, however, most studies have been conducted in larval densities that may have little or no relevance to species ecology. Here, we manipulated Drosophila melanogaster larval density based on the natural history of the species and used 3D micro-CT imaging to show a strong modulation of testes volume based on larval density: males from high larval densities generally had larger testes. Conversely, males from high densities tended (albeit not statistically significantly) to have the smallest accessory glands and ejaculatory bulb. Overall, we used micro-CT to measure male reproductive morphology in an ecologically relevant design for which the findings broadly support predictions from sexual selection theory.