Programming and Graphics

(Kiana) #1

8.3 Drop-down menus 279


(a)(b)

Figure 8.2.2 The same Pac-Man in the original and resized window.

Problems


8.2.1. Write aGlutprogram to animate (a) a spinning, and (b) a rolling disk.

8.2.2. Write aGlutprogram to animate the snowman with his head period-
ically turning left and right.

8.3 Drop-down menus


Programming drop-down menus can be a lot of fun. The sequence of callbacks
must be designed carefully according to the OpenGL protocol.


The following code implemented in the filemenu.ccgenerates a graphics
window and produces a drop-down menu with a sub-menu that offers options for
clearing the screen, drawing a teapot or a triangle, and quitting the application:


#include <freeglut.h>
using namespace std;

void showme(void);
void showmenu(void);
void menu(int);

int win;
int menuid;
int submenuid;
int drawflag=2;
Free download pdf