Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Math 155A - Introduction to Computer Graphics  Spring 2022

Project #1  Create two “5-sided tent shapes with smooth and flat colors.

Due date: Friday, April 8, 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 Tent5Project.cpp. This should be the only file you alter for your project. However, ifyou 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_Project 1_Sp2022.pdf.

FOR PROJECT #1, PLEASE DO THE FOLLOWING STEPS #0 - #11.

0.   Examine the code and online documentation for SimpleDrawModern. 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 TentProject program from the zip file Project 1Starter.zip.  Extract these into a directory named Tent5Project (or something similar). The full URL is:

~sbuss/CourseWeb/Math155A_2022Spring/Project1/Proje ct1Starter.zip.)

2.   There is an executable "Tent5Demo.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 ifyou do not have access to a PC. Experiment with this program.  Notice the following items and keyboard commands.

a.    There are two tent 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 tent are fully saturated as red, yellow, green, cyan and blue.

i.   On the top, the five corner vertices are colored bright red (1,0,0), bright yellow ( 1, 1,0), etc.

ii.   On the sides, the vertex colors are dark red (0.7, 0.0, 0.0), dark yellow (0.7, 0.7, 0.0), etc.

g.   The color on the top is white ( 1, 1, 1) and the color on the base is a gray (0.4, 0.4, 0.4)

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

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

a.    Tent5Project.cpp 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         http://www.math.ucsd.edu/~sbuss/MathCG2/, from the SimpleAnimModern folder. Direct URL is:

~sbuss/MathCG2/OpenGLsoft/SimpleAnimModern /

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:

http://www.math.ucsd.edu/~sbuss/MathCG2/OpenGLsoft/GlLinearMath/

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 Tent5Project.cpp and run this program.  This program acts somewhat like the TentDemo.exe.  However, it draws tetrahedra instead of the

tents.   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 http://www.math.ucsd.edu/~sbuss/MathCG2/ for examples of how   to use multiple geometries in one scene.

5.   Re-write the code in Tent5Project.cpp to draw 5-sided tents instead of tetrahedra.

You should use a triangle fan for the top; a triangle strip for the sides; and three     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, tent is approximately the same. (The wireframe version may show that it is triangulated  differently than the demo code.)

For this tents, rewrite the appropriate parts of mySetupGeometries() and                      myRenderScene(). You only need to create the vertex data for a SINGLE 5-sided tent in mySetupGeometries(). (That is, the same data generates both tents.) Use the           following conventions.

a.    Suggested: In mySetupGeometries(), design the tent 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 tent in the supplied TentDemo.exe.

b.   Required: Use one triangle strip, one triangle fan, and one GL_TRIANGLES.

c.    Required: Match the colors of the TentDemo program, except you do not need exactly match the darkness/brightness of the colors.

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

e.    If necessary: change the scale factor from 0.5 in myRenderScene() so that the tents are the right size for good viewing.

f.    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.

g.   Probably necessary: Change the value of NumObjects on line 60 (you will want it to equal 3: the three objects are the top faces, the side faces and the bottom faces of tent). Also, add index value for your geometric objects (to replace iTetra).  (Compare to how this is done in SimpleDrawModern.)

h.   Suggested: Use glDrawArrays commands to render the tent.

Optional: Alternately, use glDrawElements commands to render the tent.  (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?)

i.    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 tents are facing in the correct outward direction.  Be careful about specifying vertices in the right order.  There should not be any holes in your tent.  It is OK to use glFrontFace(...)  ifyou 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 tents 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 tents. 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 tent. 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 Tent5Project.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 TAs. Grading is on-demand (no reservcations) in the computer lab hours in the APM basement       computers.

Program grading: Scale of 0 to 10.  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.