Math 155A - Introduction to Computer Graphics – Fall 2022
Instructor: Sam Buss,  Univ. of California, San Diego

Project #1 – Create two “obelisk” shapes with smooth and flat colors.

Due date: Friday, October 7, 10:00pm.

Goals:  Gain some basic familiarity with triangle fans and triangle strips.  Learn how to make triangles of solid color as well as how to shade colors smoothly.  See how to use key controls to control viewpoint, and toggle wireframe and toggle culling of back faces.

What to hand in:  You will hand in to gradescope a zip containing either one or two files:

(1)   The main project source file ObeliskProject.cpp. This should be the only file you alter for your project. However, if you do change any other source file, please place it also in the zip file.

(2)   Possibly a .png file or a .bmp file showing z-fighting.

Grading will be personalized in a one-on-one in-person session with one of the four TAs or with Professor Sam Buss.  You will meet in the APM B349 (or B432) lab, and run your project either on a lab PC, or cloudlabs in a browser or on your personal laptop. You will have to discuss your source code, run the program, 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.  The grading should be completed promptly, preferably no later than the due date for the next programming assignment.

A preliminary version of the grading rubric is available at RubricDraft_Project1_Fall2022.pdf.


0.      Examine the code and online documentation for SimpleDrawModern.  (You will need to learn enough from this to create you own triangles, tringle strips and triangle fans.)
Read Chapter 1 in the PDF text, available online.

SimpleDrawModern shows the first round of OpenGL features that will be in your programs. So it is a good time to become familiar with it.

1.      Download the Obelisk Project files from the zip file  Extract these into a directory named ObeliskProject (or something similar). The full URL is: (This might download without opening window; if so check your browser’s download folder to find the download.)

2.      There is an executable "ObeliskDemo.exe" that shows (more-or-less) how your program should end up.  This is a 32-bit program and should run on most Windows machines. You can run it on the CloudLabs system if you do not have access to a PC. (Windows is likely to ask you to enter “Advanced/More options” mode to run this downloaded executable.)
Experiment with this program.  Notice the following items and keyboard commands.

a.      There are two obelisk shapes shown in the scene.   They have multicolored top and sides and a gray base.

b.      The arrow keys (left, right, up down) control the view position.  The scene moves only when you press an arrow key.  (No animation yet.) Look at from all sides, and from the top and bottom to see the colors.

c.      The "w" key toggles wire-frame mode.  

d.      The “c” key toggles whether back faces are culled. This makes a difference only in wireframe mode. Try this from multiple viewpoints.

e.      The shape on the left is smooth shaded,.  The shape on the right is flat shaded

f.       The colors on four sides and the top of the obelisk are red, yellow, green, and blue. 

                                                    i.     On the top four vertices of the sides, the four corner vertices are colored bright red (1, 0.6 ,0.6), bright yellow (1, 1 ,0.6),  and similarly with bright green and bright blue.

                                                  ii.     On the middle four and bottom four vertices of the sides, the four corner vertices are colored fully saturated red (1, 0, 0), fully saturated yellow (1, 1, 0), and similarly with fully saturated green and fully saturated red.

g.      The color on the top of the obelisk is white (1,1,1) and the color on the base is a gray (0.7, 0.7, 07)

h.      The exact same numeric values are used for colors on the smooth shaded shape.

i.       The triangles on the flat shaded figure have somewhat unexpected colors at times. You should try to understand what is happening (and we will discuss it in class lecture). 

3.      Create an empty Visual C++ project (somewhere in a permanent location where it will not deleted). Include the following eight source files:

a.      ObeliskProject.cpp, with the starter code, is in the zip file you already downloaded.

b.      ShaderMgrSAM.cpp and ShaderMgrSAM.h are part of the SimpleAnimModern program. Obtain them from the book’s website at, from the SimpleAnimModern folder. Direct URL is:

c.      LinearR3.cpp”, “LinearR3.h”, “LinearR4.cpp”, “LinearR4.h”, and “MathMisc.h are from the GlLinearMath programs. Obtain them also from the book’s website. Direct URL is:

d.      Instructions for creating a project and adding source files are in the Project #0 handout from last week. You must create a new empty C++ project, put all the .h and .cpp files in the same folder as the Solution .sln file, and add them to the project (Project … Add Existing File …”).

4.      Examine the source code in ObeliskProject.cpp and run this program.  This program acts somewhat like the ObleliskDemo.exe.  However, it draws tetrahedra instead of obelisks.   When you examine the source, do the following:

a.      Figure out how the vertices of the tetrahedron are specified with positions and colors in the routine mySetupGeometries().

b.      See how glBindVertexArray and glDrawArrays are used in myRenderScene to draw the tetrahedron.  The tetrahedron vertices are set so that the tetrahedron is centered at the origin.

c.      Understand how the loop in myRenderScene works. When i=0, it uses the shader program which does smooth shading. When i=1, it uses the shader program which does flat shading. For i=0, it shifts the tetrahedron left, down the negative x-axis.  For i=0, it shifts the tetrahedron right, along the positive x-axis.

d.      Examine the code to understand the OpenGL commands that control the wireframe mode turning off and on.  This is changed by the ‘w’ (wireframe) key, and the routine key_callback using glPolygonMode.

e.      Examine the code to understand the OpenGL commands that turn culling of back faces on and off.  This is changed by the ‘c’ (cull) key, and the routine key_callback using glEnable and glDisable.

f.       Strongly Recommended: See SimpleDrawModern’s code from Project #0 to see how to combine multiple geometries one scene. Or, see either SimpleDrawModern and SimpleAnimModern from the updated textbook website at for examples of how to use multiple geometries in one scene.

5.      MAIN TASK: Re-write the code in ObeliskProject.cpp to draw obelisks instead of tetrahedra.  You should use a triangle fan for the top; two triangle strip for the sides; and two GL_TRIANGLES for the base.  However, you do not need to build with the exact same geometry, as long as the appearance of the smoothed, non-wireframe, obelisk is approximately the same. (The wireframe version may show that it is triangulated differently than the demo code. So the colors may show in different places.)
For the obelisks, rewrite the appropriate parts of mySetupGeometries() and myRenderScene(). You only need to create the vertex data for a SINGLE obelisk in mySetupGeometries(). (That is, the same data generates both obelisks.) Use the following conventions.

a.      Suggested: In mySetupGeometries(), design the obelisk to be centered at the origin, and to fit within a circle of radius two. It does not need to exactly match the dimensions of the obelisk in the supplied ObleliskDemo.exe.

b.      When choosing vertex positions: It is important to note that in OpenGL (and in 3D graphics generally), the x,y,z axes use the following conventions: The x axis points rightwards; the y axis points upward, and the z axis points towards the viewer.  This is different from the conventions that are used in calculus, for instance.  For more on this, see the end of section I.2 (pages 6-7) in the PDF textbook.

c.      Required: Use two triangle strip, one triangle fan, and one GL_TRIANGLES.

d.     Required: More-or-less match the colors of the ObleliskDemo program, except you do not need exactly match the darkness/brightness of the colors.

e.      If necessary: adjust the translations in myRenderScene() to appropriately position the obelisks for good viewing.

f.       If necessary: change the scale factor from 0.5 in myRenderScene() so that the obelisks are the right size for good viewing. There is also a more general version of the Mult_glScale function that scales separately in the x, y, z directions (it is in the code,  but commented out).

g.      Probably not necessary: You can also adjust the values of Xmin, Xmax, Ymin, Ymax, Zmin and Zmax.  These values control what (x,y,z) points can be rendered without going outside the borders of the window or being too near or too far away from the viewer.

h.     Probably necessary: Change the value of NumObjects on line 63 (you will probably want it to equal 4: the three objects are the top faces, the two sets of side faces and the bottom faces of obelisk). Also, add index value for your geometric objects (to replace iTetra).  (Compare to how this is done in SimpleDrawModern.)

i.       Suggested: Use glDrawArrays commands to render the obelisk.
Optional: Alternately, use glDrawElements commands to render the obelisk.  (For glDrawElements see the online Chapter 1, or the BasicDrawModes sample code at the book’s web site.) If you use glDrawElements, vertices can be reused, but you will need to give two different versions of the five base vertices.  (Why?)

j.       Suggested: Use a generic vertex attribute for the base vertices, that is by using glVertexAttrib3f(). You can receive extra points in your score for doing this that make up for points missed elsewhere.

6.      Be sure that all faces of the obelisks are facing in the correct outward direction.  Be careful about specifying vertices in the right order.  There should not be any holes in your obelisk.  It is OK to use glFrontFace(...)  if you wish to switch between CCW and CW modes.

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 obelisks are rotated in wire frame mode?  Are there any artifacts due to aliasing? (E.g., jagged lines, or crawling visual artifacts.)  Can you see any z-fighting?  For z-fighting, you will see isolated pixels that are the wrong color. (See item 10.)  These effects may be subtle.   If you have trouble seeing aliasing problems, try slowing down the motion by change the value of deltaTheta to a smaller value such as 0.005 or 0.002 instead of 0.01: then recompile and hold down arrow key and watch the edges of the wireframe obelisks. To see z-fighting, use only wire-frame mode and be sure that back faces are not culled.  Then look for pixels popping up in the wrong color: this will be the most visible on the top edges of the flat shaded polygon. It is the edges of the front face and back faces that are z-fighting with each other. It is also possible that two front faces create z-fighting.
These phenomena may well be different on different machines!  There is a tendency for OpenGL implementations of lines and of wire-frame mode to have small bugs and this may be part of what you see.)  However, you may not be able to create z-fighting on a home computer! It does not happen on most laptops.
Be ready to discuss what you see with your TA during grading. 

9.      If you are able to see any z-fighting: Make a screenshot showing the z-fighting and save the image as PNG or BMP file. z-fighting will be visible only in wire-frame mode, only if back faces are not culled, and mostly on the flat-shaded obelisk. z-fighting will show one of the edges having a few pixels replaced with a different color (due the fact that the same edge is drawn twice, with different colors). The best way to find the z-fighting is to tilt the image by rotating up or down, making the window large to enlarge the image, and slowing down the rate by replacing the value of the variable deltaAngle to a smaller value such as 0.005.   Then use the arrow keys to rotate, and watch carefully for pixels flashing different colors. The lab computers are usually able to show z-fighting, but most other computers (with different implementations of OpenGL) might not.
You can grab a screen shot using the Snipping Tool on Windows.  Another way to form the screenshot of a window on a PC is to hold down the “ALT” and the “RIGHT-SHIFT” buttons and press the “PRINT SCREEN” (PRT-SCN) buttons. (This may work slightly differently on some Windows machines.) Then open an image program such as Paint, paste the screenshot image in, and save to disk as a .bmp or .png file.  It is recommended to not use jpeg files and especially not to use a photo editor to view the file, as they will reduce the image quality.

10.   Turn in the project by uploading a zip file to gradescope.  The zip file should include the modified source file ObeliskProject.cpp, and optionally a .bmp or .png file showing z-fighting in your Project_1.  The gradescope files are primarily to time-stamp your project; they do not suffice to get graded.

11.   To get graded, see Professor Buss or (after the due date) one of the TA’s. Grading is on-demand (no reservcations) in the computer lab hours in the APM basement computers.

Program grading: Scale of 0 to 20.  Personal grading session with a TA or the professor in the computer lab.  For grading, be ready to discuss any of the above topics, plus be prepared to make small modifications to the source code and recompile.