Question: line drawing with OpenGL Given five vertices v 1 = (0, 80), v 2 = (-30, -60), v 3 = (70, 0), v 4 =

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.

here is my code

#include // include GLUT library

void drawPoints()

{glBegin(GL_POINTS); // use the default point size: 1

glColor3f(1, 0, 0); // specify drawing color: red

glVertex2i(5, -5); // specify a point location

glVertex2i(-120, 70); // 2nd point

glVertex2i(100, 100); // 3rd point

glEnd();

glPointSize(5); // change point size to 5

glColor3f(0, 0, 1); // change drawing color to blue

glBegin(GL_POINTS);

glVertex2f(8.3, -9.7);

glVertex2f(-106.8, 71.5);

glColor3i(0, 1, 0); // a common error !!! (when use an integral type for parameters)

glVertex2f(110.0, 105.5);

glEnd();

glPointSize(1); // change point size back to 1

glBegin(GL_POINTS); // use points to form X-/Y-axes

glColor3f(0, 0, 0); // change drawing color to black

for (int x=-150; x<=150; x++) // draw X-axis

glVertex2i(x, 0);

for (int y=-150; y<=150; y++) // draw Y-axis

glVertex2i(0, y);

glEnd();

}

void myInit()

{glClearColor(1, 1, 1, 0); // specify a background clor: white

gluOrtho2D(-200, 200, -200, 200); // specify a viewing area

}

void myDisplayCallback()

{glClear(GL_COLOR_BUFFER_BIT); // draw the background

drawPoints();

glFlush(); // flush out the buffer contents

}

void main(int argc, char ** argv)

{//glutInit(& argc, argv); // optional in our environment

glutInitWindowSize(400, 400); // specify a window size

glutInitWindowPosition(100, 0); // specify a window position

glutCreateWindow("Simple Point Drawing"); // create a titled window

myInit(); // setting up

glutDisplayFunc(myDisplayCallback); // register a callback

glutMainLoop(); // get into an infinite loop

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!