Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

line drawing with OpenGL Given five vertices v 1 = (0, 80), v 2 = (-30, -60), v

ID: 3890701 • Letter: L

Question

line drawing with OpenGL

Given five vertices v1 = (0, 80), v2 = (-30, -60), v3 = (70, 0), v4 = (-70, 0), v5 = (30, -60), and a set of stipple patterns for line drawing below (a shaded cell represents 1 and a white cell represents 0), assuming factor=1, modify the program so that it replaces the smiley with an image determined by the five line segments (v1, v2), (v2, v3), (v3, v4), (v4, v5), and (v5, v1) (keep the X- and Y-axis unchanged). The program should allow a user to determine whether the line segments are displayed in solid or one of the given patterns before they are drawn. You may determine the color and width of each line segment as you wish.

Note:

1) When you need to use header file iostream in your program, include it before including file glut.h.

2) Since a display-callback function does not accept any parameter, a global variable is needed if one wants to pass a data value into a display-callback or a function called either directly or indirectly by a display-callback.

3) You may add operations for user input in function main( ) or a function called either directly or indirectly by function main( ), but NOT in the display-callback function or a function called either directly or indirectly by the display callback function (you will learn the reason later).

4) Carefully design your user interface, so that a user would know exactly what to enter.

Explanation / Answer


OpenGL’s drawing works in two stages. First, a list of vertices is passed to the vertex shader. The vertex shader is basically a small function that transforms every vertex (in the model coordinate system) to a new position (the screen coordinate system), so that you can reuse the same array of vertices for every frame, but still do things like rotate, translate, or scale the objects.
Three consecutive vertices form a triangle. All pixels in that area are then processed by the fragment shader, also called the pixel shader. While the vertex shader is run once for every vertex in the source array, the fragment shader is run once for every pixel in a triangle to decide what color to assign to that pixel.