First, I copied the code available in the TP and I created a mesh for a sphere. The mesh is not optimized because I used the spherical coordinates system. Multiple vertices are at the same location. But the implementation is simple and we will have only a few planets so it’s good enough. Then I implemented the Phong lighting model.


Then I started to use objects to represent the planets. Each will have a reference to the unitary sphere mesh, that will be scaled, rotated, and translated before each rendering. This is a way to save memory, as everything needs to be computed again as the planets move.

Then I implemented the solar system. Planets can have a reference to their parent, another planet. This will be used later to calculate the position of orbiting planets very easily. Then I changed the light so that it comes from the sun. I just had to take the position of the faces to calculate it, as the source, the sun is at 0,0,0. For the moment, the light in the sun is not well calculated, as the light is from the interior, we only see the diffuse light.


Then I added the rotation of the planets and colored them. At first, I thought having a blue earth and gray moon is a better choice of color than the one suggested in the TP. I also fixed the light in the sun, by sending a Kdiffuse constant in the shader. Then I added some textures, and added one to the sun too.


Then I added some extras. I first added some movement to the camera. You can zoom to the planets with the scroll, and turn around by dragging. You can also follow another planet by using the arrows of the keyboard. Then I added a skybox to the scene, following a tutorial on learnopengl.com.

Finally, it used higher quality images, and enabled mipmap to have better results on far away planets. I also used a night map on the earth to add lights on the opposite side of the sun.
