In this assignment you will implement a simple graphics package using the OpenGL graphics library.Using inheritance,geometric objects will be displayed in awindow.The lab workstations all run X11 so there is no problem there.When you log into the server remotely,besure to specify the -X option, as in: ssh -X email@example.com Before you log into the server make sure you have an X11 client running on your own workstation.
2. Program Speciﬁcation
The program is presented in the form of a Unix man(1) page.
NAME gdraw—drawing program displaying objects in a window
SYNOPSIS gdraw [ options][ﬁlename]
OPTIONS All options are recognized by getopt(3).
-@ ﬂags The ﬂags speciﬁed are passed to the debugging macro.Debug output is printed to the standard error.
-w width The initial width of the window.Default : 640.
-h height The initial height of the window.Default : 480.
OPERANDS Commands are read from the ﬁle whose name is given as an operand. If no ﬁlename is given, commands are read from the standard input.
COMMANDS When the program begins,awindow is created for displaying information, whichconsists of text and geometric objects of various kinds.The project proceeds in two parts:
(a) Shapes are deﬁned in terms of their sizes (length, width, or vertices).
(b) Objects are drawn in the window by drawing commands,after which they maybealtered by keyboard commands.
Sizes,lengths,widths,and coordinates are all ﬂoating point numbers,and measure pixels.
Colors maybespeciﬁed by name using one of the names in the ﬁle rgb.txt,or by their hexadecimal values in the form 0xRRGGBB, where RR, GG,and BB are the red, green, and blue components eachspeciﬁed as two hexadecimal digits in the range 00 to FF.
CMPS-109 • Spring 2015 • Program 4 • OOP and Inheritance 2 of 5
The define command makes a record of the deﬁnition of an shape and makes it available later for a drawcommand. The draw command creates an object in the screen’sobject list, to be displayed when the program starts.
The following commands are recognized. Eachcommand is on a line by itself and terminates with the newline character.Ifthe last character on a line is a backslash (\), the command is continued onto the next line.
# … Acomment line is ignored, as are empty lines and lines consisting only of white space.
define name text font words… Atext object is created by concatenating all of the words together,each separated from the next by spaces.The font is any of the seven GLUT bitmap fonts: • Fixed-8×13 • Fixed-9×15 • Helvetica-10 • Helvetica-12 • Helvetica-18 • Times-Roman-10 • Times-Roman-24
define name ellipse width height An ellipse is speciﬁed with the major and minor diameters speciﬁed. When drawn, the drawing coordinate is the center.
define name circle diameter Acircle is just an ellipse whose length and width are equal.
define name polygon x0 y0 x1 y1 x2 y2 … Apolygon is speciﬁed with the number of vertices being equal to the number of (x, y)coordinates given. The polygon must be convex (each interior angle less than 180 degrees). The convexity is not veriﬁed by the program, so the appearance of a non-convex polygon is undeﬁned. The center of the polygon is at (x, y), i.e., at the average of all the x coordinates and the average of the y coordinates.After computing the average, it is subtracted from eachofthe vertices to normalize them. Forexample,ifthe vertices are speciﬁed as shown in the left side of the diagram, they are normalized to that shown on the right side,sothat (x, y) changes from (. 5,. 5)to(0, 0).
(0,0) (1 , 0)
(0(1 ,1) ,1)
(. 5,. 5)
(−.5, −.5)(+.5, −.5)
(+.5, + (.5) −.5, +.5)
CMPS-109 • Spring 2015 • Program 4 • OOP and Inheritance 3 of 5
define name rectangle width height Arectangle with the given width and height is deﬁned with strictly horizontal and vertical lines with the given thickness.When drawn, the drawing coordinates will be the center.
define name square width Asquare is a rectangle with equal width and height.
define name diamond width height Adiamond’swidth is from the leftmost to rightmost point and its height is from topmost to bottommost height. The draw command speciﬁes its center.
define name triangle x0 y0 x1 y1 x2 y2 Atriangle is just another name for a polygon.
define name right_triangle width height Deﬁne a right triangle with width the horizontal bar extending to the right and height the vertical bar.
define name isosceles width height The width speciﬁes the width of the base,and the height speciﬁes the perpendicular distance from the base to the apex.
define name equilateral width Makes an isosceles triangle that is also equilateral.
border color thickness Speciﬁes the thickness in pixels of the border surrounding the selected object, and its color.Defaults : red, 4.
moveby pixels The move parameter indicates how many pixels an object moves when directed by one keystroke.Default : 4.
draw color name xcenter ycenter Draws an object with the center at (x, y)using the color speciﬁed.
KEYBOARD INPUT Once the input ﬁle is ﬁnished, the keyboard is used to command the movements of the objects.The following keystrokes control the program:
q Quit (exit the program). h Move the selected object left. j Move the selected object down. k Move the selected object up. l Move the selected object right. n Set the selection to the next object. p Set the selection to the previous object. 0 … 9 Set the selection to objects 0 through 9, respectively.
An object is alwaysdisplayed using the coordinates of the center.Ifanobject is moved off the window,itappears at the other end of the window.That is,if the x or y coordinate exceeds the width (height) of the windor,itisset to 0. If it becomes negative,itisset to the width (height). The selected object is
CMPS-109 • Spring 2015 • Program 4 • OOP and Inheritance 4 of 5
alwayssurrounded by a border to make it visible.For objects 0 through 9, the object’snumber is displayed in the center of the object.
0Noerrors were detected.
1Errors were detected and messages printed to the standard error.
OpenGL and GLUT will be used to displaythe window.See the short example programs in the misc/ subdirectory.Starter code is in the code/ subdirectory.For documentation, Google using the terms ‘‘OpenGL’’ and/or ‘‘GLUT’’and the name of the function, then look for results naming the web pages in www.opengl.org/documentation Following are some functions you might need: glBegin glClear glClearColor glColor3ub glColor3ubv glEnable glEnd glFlush glHint glLineWidth glLoadIdentity glMatrixMode glOrtho glPointSize glPopMatrix glPushMatrix glRasterPos2f glRasterPos2i glRotatef glTranslatef glVertex2f glViewport gluOrtho2D glutAddMenuEntry glutAddSubMenu glutAttachMenu glutBitmapCharacter glutBitmapHeight glutBitmapLength glutBitmapString glutCloseFunc glutCreateMenu glutCreateWindow glutDisplayFunc
CMPS-109 • Spring 2015 • Program 4 • OOP and Inheritance 5 of 5
glutEntryFunc glutInit glutInitDisplayMode glutInitWindowPosition glutInitWindowSize glutKeyboardFunc glutKeyboardUpFunc glutMainLoop glutMotionFunc glutMouseFunc glutPassiveMotionFunc glutPostRedisplay glutReshapeFunc glutSetIconTitle glutSetWindowTitle glutSpecialFunc glutSpecialUpFunc glutSwapBuffers glutTimerFunc glutWireTeapot
4. What to Submit
Submit all C++ source ﬁles and the Makefile.Ifyou are doing pair programming, also submit the PARTNER ﬁle.