CSE 167 - Introduction
to Computer Graphics - Fall 2004
Instructor: Sam Buss, Univ. of California, San Diego
Project #2 - Create two polygonal shapes with six sides.
Due Date: Tuesday, October 19, midnight.
Goals: Gain some basic familiarity with triangle fans and quad-strips. Learn how to make a triangles or quadrilateral of solid color as well as how to shade colors smoothly. This assignment is somewhat simpler than Project #3, and you might want to finish it ahead of the due date so as to have a chance to get a head start on Project #3..
What to hand in: Make a directory called
TwoShapes in your CSE 167 home directory (also called the CSE167
"storage" directory). This folder is under Class Resources, not your "My Documents"
file modification dates will serve as a time stamp so we will know files have
been turned in on time. Please in that directory, all your source
files and project files (including .vcproj and .sln files).
Grading will be personalized and one-on-one with a TA or with Sam Buss. Your program must run on the PC lab, you must come into the PC lab and meet one of us. You will have to show your source code, run the program, possibly make changes on the spot to your program and recompile as requested by the grader, and be able to explain how your program works and why it renders what it does. Your files should be complete and project must recompile in the home (storage) directory. You will then come see a TA to get your work graded. This grading MUST be done by Tuesday, October 26, and we prefer that it be done earlier. If too many people procrastinate on getting graded, not everyone will have time to be graded!
FOR THIS PROJECT #2, DO THE FOLLOWING STEPS #1 - #9. Your main task is to rewrite the program TwoShapes.cpp so that it generates the same images as TwoShapesDemo.exe.
1. Downloading files for Project #2. Download the TwoShapes program from the zip file Fall04TwoShapesProjectTwo.zip. Extract these into a directory named TwoShapes.
2. There is an executable "TwoShapesDemo.exe" that shows how your program should up. Experiment with with this program. Try out the following keyboard commands..
There are two shapes shown, with eighteen sides each. They have six vertical sides, the top has six triangles, and the bottom also has six triangles..
The arrow keys (left, right, up down) control the view position. The "w" key toggles wire-frame mode. (Optional: if the rate of movement is too slow, press "R" to make it faster. If it is too fast, press "r" to make the rate slower.
The shape on the left is smooth shaded, (GL_SMOOTH option). The shape on the right is flat-shaded (GL_FLAT option). The colors on the shape on the right are red, yellow, green, cyan, blue, and magenta. The colors on the shape on the left are smoothly varying between these colors.
The following numerical value of colors are used for the three red faces on the flat shaded shape. The bottom red face has color (0.5, 0.0, 0.0). The red side face has color (1.0, 0.0, 0.0). The top red face has color (1.0, 0.5, 0.5).
Similar numeric values are used for colors on the smooth shaded shape. The top vertex is colored white and the bottom vertex black --- on the smooth shaded shape.
3. Find the solution "TwoShapes.sln". Examine the source code and run this program. This program looks somewhat like the TwoShapesDemo.exe. However, it draws cubes instead of the 18-sided shapes. When you examine the source, do the following:
Examine the code and understand how the cubes are specified (usings GL_QUADS and as GL_QUAD_STRIP.)
Examine the code to understand the OpenGL commands that control the shading (flat or smooth).
Examine the code to understand the OpenGL commands that turn wire frame mode off and on.
Find every place in the code where glutPostRedisplay is called. Understand why is it called in these places.
Your job is to write TwoShapes.cpp so that it is functionally the same as TwoShapesDemo.exe.
4. Re-write the code for the shape on the right. In place of the code given for the cube on the right, write code that draws the shape shown in TwoShapesDemo. Use one quad strip and two triangle fans to build the shape. Use flat shading and mimic the colors in TwoShapesDemo. (Do not use GL_POLYGON.)
5. Re-write the code for the shape on the left. In place of the code given for the cube on the left, write code that draws the shape shown in TwoShapesDemo. Use one quad strip and two triangle fans to build the shape. Use smooth shading and mimic the colors in TwoShapesDemo. (Do not use GL_POLYGON.)
6. Be sure that all faces of the shapes are facing in the correct outward direction. It is recommended that you be careful about specifying vertices in the right order. You may *not* disable the back face culling that is used in the supplied code! There should not be any holes in your cubes. It is OK to use glFrontFace(...) if you want to.
7. Understand the difference between flat and smooth shading. Be able to discuss the differences with the TA grading your program, and to explain how the shading is caused by the source code.
8. Examine carefully the way the program works in wire frame mode. Do you notice anything unusual as the cubes are rotated in wire frame mode? Are there any artifacts due to aliasing? Can you see any z-fighting? If you have trouble seeing aliasing problems, try slowing down the motion by pressing "r" a few times, then hold down arrow in key and watch the edges of the cubes. Try this in both wire-frame mode and non-wire-frame mode. Be ready to discuss what you see with your TA when you are being graded. (These phenomena may be different on different machines! There is a tendency for OpenGL implementations of lines and of wire-frame mode to have small bugs.)
9. Learn about the rest of the options for glBegin() and glEnd(). These include GL_POLYGON, GL_TRIANGLES, and GL_TRIANGLE_STRIP.
Grading: On a scale of 1-8. Personal grading session with a TA or the professor.