Overview
In the previous posts drawing a textured cube were explained. Also, the implementation of the LightingUtil and LightedTexCube were covered.
In this post we will try to draw a textured cube with lighting interactively. The cube looks as shown above. The cube looks elongated because aspect ratio is not applied.
Details
The purpose of Lesson06 is to create a lighted textured cube and work with it interactively with different types of light to understand nuances of lighting.
System class diagram
The scene class overrides camera with an instance of ThreeDCamera. It has an instance of LightedTexCube called cube derived from TexturedCube class.
Implementation
Scene
The functionality is implemented in the Scene class derived from BaseScene class.
The Init method calls
- BaseScene::Init to create hosting window and OpenGL Context.
- It also attaches camera to a ThreeDCamera class object. This camera processes keyboard and mouse inputs as explained earlier.
- It creates an input dialog to work with lighting settings interactively.
- It calls init function on the LightedTexCube object to populate VBO/EBO buffers and bind them.
- Load textures from the image file
- It also compiles and links shader programs.
The DrawScene method draws the cube with texture wrapped and rotates as per keyboard or mouse inputs. The lighting settings are taken from the light instance of LightingUtil of the cube object.
The Cleanup method releases the resources related to VBO/EBO, Texture related resources and shader programs.
The message handler for IDOK is called when Apply button is pressed after updates are made in the input dialog. It refreshes the display.
The message handler for IDCANCEL is called when in Cancel button is pressed the input dialog. It calls
OnCloseWindow to destroy window.
Finally the WM_CLOSE event is handled in OnCloseWindow function and the window is destroyed and application is shutdown when the window is closed or Escape key is pressed.
The output looks as shown in the top.
No comments:
Post a Comment