Description
Write a program that draws a color-changing cube.
-
- Set the window title and the window size to (480,480).
- Start from the code in 7-Lighting&Shading slides. Draw a flat-shaded cube. Make sure FDPHUDPDQLSXODWLRQVKRUWFXWVěĜěĜěĜěZĜZRUN C. Use the following light setting:
lightPos = (3.,4.,5.,1.)
glLightfv(GL_LIGHT0, GL_POSITION, lightPos)
ambientLightColor = (.1,.1,.1,1.)
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLightColor)
specularObjectColor = (1.,1.,1.,1.)
glMaterialfv(GL_FRONT, GL_SPECULAR, specularObjectColor)
glMaterialfv(GL_FRONT, GL_SHININESS, 10)
- If you press or repeat a key, the diffuse & specular color of the light and the ambient & diffuse color of the object should be changed as shown in the Table:
| Key | Action |
| A | Change the light color to red |
| S | Change the light color to green |
| D | Change the light color to blue |
| F | Change the light color to white |
| Z | Change the object color to red |
| X | Change the object color to green |
| C | Change the object color to blue |
| V | Change the object color to white |
Write a program that draws a smooth-shaded cube.
-
- Set the window titleand the window size to (480,480).
- Start from the code in 7-Lighting&Shading slides. Make sure camera manipulation
VKRUWFXWVěĜěĜěĜěZĜZRUN
- Use glDrawElements(), not glDrawArray(). Refer the code in 6-Viewing&projection2, Mesh slides.
- Hint: In Gouraud shading, one vertex has only one normal. This makes using glDrawElements() easier.
- Use the following normal vector data:
- If you press or repeat a key, the ambient & diffuse color of the object should be changed as shown in the Table:
| Key | Action |
| R | On/Off the object color of red |
| G | On/Off the object color of green |
| B | On/Off the object color of blue |
- Expected result: Uploaded LabAssignment7-2.mp




