Projecting a 3D scene by generating a high-quality hologram in real time is crucial in many applications, such as virtual and augmented reality and interactive learning. Existing computergenerated hologram methods typically rely on iterative algorithm or deep learning techniques to digitally generate holograms, which are time-consuming and computationally burdensome. Here, we propose a computer-free, physical diffractive network capable of optically generating holograms (OGH) with extended depth of focus from unknown objects at the speed of light. This OGH diffractive network is composed of passive diffractive layers designed by using self-supervised learning. To learn the mapping between the hologram and the target image, the parameters of each layer, each with tens of thousands of diffractive features, are adjusted through the back-propagation algorithm, by minimizing the customized loss function between the diffractive pattern and object image. After training, which is a one-time effort, the parameters of diffractive layers are fixed, forming a physical network capable of encoding unknown objects into corresponding holograms at the speed of light, without the need for a computer or any digital algorithm. The accuracy of the holograms generated by trained diffractive networks is guaranteed by the quality of the reconstructed image. The tested results demonstrated that our all-optical holoencoder can successfully generalize to optically generate holograms from different types of unknown objects and exhibits an extended depth of focus at a reconstruction distance. Our diffractive-based OGH network and the underlying design framework open a new route to optically generate holograms and enable applications in real-time holography display driven by the computing speed facilitated by photonics.