more cleanup in callbackmaker demo, now showing best practice for
[freeglut] / progs / demos / CallbackMaker / CallbackMaker.c
1 /* CallbackMaker.c */
2 /*
3  * Program to invoke all the callbacks that "freeglut" supports
4  */
5
6
7 #include <GL/freeglut.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <stdarg.h>
11
12 static int sequence_number = 0 ;
13
14 int windows[2] = {0};
15
16 /* define status vars showing whether given callback has been called for given window */
17 #define CALLBACK_CALLED_VAR(name) int name##_called[2] = {0};
18 #define CALLBACK_1_VAR(name,field) int name##_##field[2], name##_seq[2] = {-1};
19 #define CALLBACK_2_VARS(name,field1,field2) int name##_##field1[2], name##_##field2[2], name##_seq[2] = {-1};
20 #define CALLBACK_3_VARS(name,field1,field2,field3) int name##_##field1[2], name##_##field2[2], name##_##field3[2], name##_seq[2] = {-1};
21 #define CALLBACK_4_VARS(name,field1,field2,field3,field4) int name##_##field1[2], name##_##field2[2], name##_##field3[2], name##_##field4[2], name##_seq[2] = {-1};
22 CALLBACK_CALLED_VAR(reshape);
23 CALLBACK_2_VARS(reshape,width,height);
24 CALLBACK_CALLED_VAR(key);
25 CALLBACK_3_VARS(key,key,x,y);
26 CALLBACK_CALLED_VAR(keyup);
27 CALLBACK_3_VARS(keyup,key,x,y);
28 CALLBACK_CALLED_VAR(special);
29 CALLBACK_3_VARS(special,key,x,y);
30 CALLBACK_CALLED_VAR(specialup);
31 CALLBACK_3_VARS(specialup,key,x,y);
32 CALLBACK_CALLED_VAR(visibility);
33 CALLBACK_1_VAR(visibility,vis);
34 CALLBACK_CALLED_VAR(joystick);
35 CALLBACK_4_VARS(joystick,a,b,c,d);
36 CALLBACK_CALLED_VAR(mouse);
37 CALLBACK_4_VARS(mouse,button,updown,x,y);
38 CALLBACK_CALLED_VAR(mousewheel);
39 CALLBACK_4_VARS(mousewheel,number,direction,x,y);
40 CALLBACK_CALLED_VAR(motion);
41 CALLBACK_2_VARS(motion,x,y);
42 CALLBACK_CALLED_VAR(passivemotion);
43 CALLBACK_2_VARS(passivemotion,x,y);
44 CALLBACK_CALLED_VAR(entry);
45 CALLBACK_CALLED_VAR(close);
46 /*CALLBACK_CALLED_VAR(overlaydisplay);
47 CALLBACK_CALLED_VAR(windowstatus);
48 CALLBACK_CALLED_VAR(spacemotion);
49 CALLBACK_CALLED_VAR(spacerotation);
50 CALLBACK_CALLED_VAR(spacebutton);
51 CALLBACK_CALLED_VAR(buttonbox);
52 CALLBACK_CALLED_VAR(dials);
53 CALLBACK_CALLED_VAR(tabletmotion);
54 CALLBACK_CALLED_VAR(tabletbutton);
55 CALLBACK_CALLED_VAR(menustatus);*/
56 /* menudestroy is registered on each menu, not a window */
57 int menudestroy_called = 0 ;
58 /* menustatus and menustate are global callbacks, set for all menus at the same time */
59 int menustatus_called = 0;
60 int menustate_called = 0;
61
62 #define STRING_LENGTH   10
63
64 static void
65 bitmapPrintf (const char *fmt, ...)
66 {
67     static char buf[256];
68     va_list args;
69
70     va_start(args, fmt);
71 #if defined(WIN32) && !defined(__CYGWIN__)
72     (void) _vsnprintf (buf, sizeof(buf), fmt, args);
73 #else
74     (void) vsnprintf (buf, sizeof(buf), fmt, args);
75 #endif
76     va_end(args);
77     glutBitmapString ( GLUT_BITMAP_HELVETICA_12, (unsigned char*)buf ) ;
78 }
79
80 static int
81 getWindowAndIdx(int *winIdx)
82 {
83     int window = glutGetWindow();
84
85     if (winIdx)
86         (*winIdx) = window==windows[0]?0:1;
87
88     return window;
89 }
90
91 static void 
92 Display(void)
93 {
94   int winIdx;
95   int window = getWindowAndIdx(&winIdx);
96   glClear ( GL_COLOR_BUFFER_BIT );
97
98   glDisable ( GL_DEPTH_TEST );
99   glMatrixMode ( GL_PROJECTION );
100   glPushMatrix();
101   glLoadIdentity();
102   glOrtho(0, glutGet ( GLUT_WINDOW_WIDTH ), 
103           0, glutGet ( GLUT_WINDOW_HEIGHT ), -1, 1 );
104   glMatrixMode ( GL_MODELVIEW );
105   glPushMatrix ();
106   glLoadIdentity ();
107   glColor3ub ( 0, 0, 0 );
108   glRasterPos2i ( 10, glutGet ( GLUT_WINDOW_HEIGHT ) - 20 );    /* 10pt margin above 10pt letters */
109
110   if ( reshape_called[winIdx] )
111   {
112     bitmapPrintf ( "Reshape %d:  %d %d\n", reshape_seq[winIdx], reshape_width[winIdx], reshape_height[winIdx] );
113   }
114
115   if ( key_called[winIdx] )
116   {
117     bitmapPrintf ( "Key %d:  %d(%c) %d %d\n", key_seq[winIdx], key_key[winIdx], key_key[winIdx], key_x[winIdx], key_y[winIdx] );
118   }
119
120   if ( special_called[winIdx] )
121   {
122     bitmapPrintf ( "Special %d:  %d(%c) %d %d\n", special_seq[winIdx], special_key[winIdx], special_key[winIdx], special_x[winIdx], special_y[winIdx] );
123   }
124
125   if ( visibility_called[winIdx] )
126   {
127     bitmapPrintf ( "Visibility %d:  %d\n", visibility_seq[winIdx], visibility_vis[winIdx] );
128   }
129
130   if ( keyup_called[winIdx] )
131   {
132     bitmapPrintf ( "Key Up %d:  %d(%c) %d %d\n", keyup_seq[winIdx], keyup_key[winIdx], keyup_key[winIdx], keyup_x[winIdx], keyup_y[winIdx] );
133   }
134
135   if ( specialup_called[winIdx] )
136   {
137     bitmapPrintf ( "Special Up %d:  %d(%c) %d %d\n", specialup_seq[winIdx], specialup_key[winIdx], specialup_key[winIdx], specialup_x[winIdx], specialup_y[winIdx] );
138   }
139
140   if ( joystick_called[winIdx] )
141   {
142     bitmapPrintf ( "Joystick %d:  %d %d %d %d\n", joystick_seq[winIdx], joystick_a[winIdx], joystick_b[winIdx], joystick_c[winIdx], joystick_d[winIdx] );
143   }
144
145   if ( mouse_called[winIdx] )
146   {
147     bitmapPrintf ( "Mouse %d:  %d %d %d %d\n", mouse_seq[winIdx], mouse_button[winIdx], mouse_updown[winIdx], mouse_x[winIdx], mouse_y[winIdx] );
148   }
149
150   if ( mousewheel_called[winIdx] )
151   {
152     bitmapPrintf ( "Mouse Wheel %d:  %d %d %d %d\n", mousewheel_seq[winIdx], mousewheel_number[winIdx], mousewheel_direction[winIdx], mousewheel_x[winIdx], mousewheel_y[winIdx] );
153   }
154
155   if ( motion_called[winIdx] )
156   {
157     bitmapPrintf ( "Motion %d:  %d %d\n", motion_seq[winIdx], motion_x[winIdx], motion_y[winIdx] );
158   }
159
160   if ( passivemotion_called[winIdx] )
161   {
162     bitmapPrintf ( "Passive Motion %d:  %d %d\n", passivemotion_seq[winIdx], passivemotion_x[winIdx], passivemotion_y[winIdx] );
163   }
164
165   glMatrixMode ( GL_PROJECTION );
166   glPopMatrix ();
167   glMatrixMode ( GL_MODELVIEW );
168   glPopMatrix ();
169   glEnable ( GL_DEPTH_TEST );
170
171   printf ( "%6d Window %d Display Callback\n",
172             ++sequence_number, window ) ;
173   glutSwapBuffers();
174 }
175
176 static void
177 Warning(const char *fmt, va_list ap)
178 {
179     printf("%6d Warning callback:\n");
180
181     /* print warning message */
182     vprintf(fmt, ap);
183 }
184
185 static void
186 Error(const char *fmt, va_list ap)
187 {
188     char dummy_string[STRING_LENGTH];
189     printf("%6d Error callback:\n");
190
191     /* print warning message */
192     vprintf(fmt, ap);
193
194     /* terminate program, after pause for input so user can see */
195     printf ( "Please enter something to exit: " );
196     fgets ( dummy_string, STRING_LENGTH, stdin );
197
198     /* Call exit directly as freeglut is messed
199      * up internally when an error is called. 
200      */
201     exit(1);
202 }
203
204 static void 
205 Reshape(int width, int height)
206 {
207   int winIdx;
208   int window = getWindowAndIdx(&winIdx);
209   printf ( "%6d Window %d Reshape Callback:  %d %d\n",
210             ++sequence_number, window, width, height ) ;
211   reshape_called[winIdx] = 1 ;
212   reshape_width[winIdx] = width ;
213   reshape_height[winIdx] = height ;
214   reshape_seq[winIdx] = sequence_number ;
215   glViewport(0,0,width,height);
216   glutPostRedisplay () ;
217 }
218
219 static void 
220 Key(unsigned char key, int x, int y)
221 {
222   int winIdx;
223   int window = getWindowAndIdx(&winIdx);
224   printf ( "%6d Window %d Keyboard Callback:  %d %d %d\n",
225             ++sequence_number, window, key, x, y ) ;
226   key_called[winIdx] = 1 ;
227   key_key[winIdx] = key ;
228   key_x[winIdx] = x ;
229   key_y[winIdx] = y ;
230   key_seq[winIdx] = sequence_number ;
231   glutPostRedisplay () ;
232 }
233
234 static void 
235 Special(int key, int x, int y)
236 {
237   int winIdx;
238   int window = getWindowAndIdx(&winIdx);
239   printf ( "%6d Window %d Special Key Callback:  %d %d %d\n",
240             ++sequence_number, window, key, x, y ) ;
241   special_called[winIdx] = 1 ;
242   special_key[winIdx] = key ;
243   special_x[winIdx] = x ;
244   special_y[winIdx] = y ;
245   special_seq[winIdx] = sequence_number ;
246   glutPostRedisplay () ;
247 }
248
249 static void 
250 Visibility(int vis)
251 {
252   int winIdx;
253   int window = getWindowAndIdx(&winIdx);
254   printf ( "%6d Window %d Visibility Callback:  %d\n",
255             ++sequence_number, window, vis ) ;
256   visibility_called[winIdx] = 1 ;
257   visibility_vis[winIdx] = vis ;
258   visibility_seq[winIdx] = sequence_number ;
259   glutPostRedisplay () ;
260 }
261
262 static void 
263 KeyUp(unsigned char key, int x, int y)
264 {
265   int winIdx;
266   int window = getWindowAndIdx(&winIdx);
267   printf ( "%6d Window %d Key Release Callback:  %d %d %d\n",
268             ++sequence_number, window, key, x, y ) ;
269   keyup_called[winIdx] = 1 ;
270   keyup_key[winIdx] = key ;
271   keyup_x[winIdx] = x ;
272   keyup_y[winIdx] = y ;
273   keyup_seq[winIdx] = sequence_number ;
274   glutPostRedisplay () ;
275 }
276
277 static void 
278 SpecialUp(int key, int x, int y)
279 {
280   int winIdx;
281   int window = getWindowAndIdx(&winIdx);
282   printf ( "%6d Window %d Special Key Release Callback:  %d %d %d\n",
283             ++sequence_number, window, key, x, y ) ;
284   specialup_called[winIdx] = 1 ;
285   specialup_key[winIdx] = key ;
286   specialup_x[winIdx] = x ;
287   specialup_y[winIdx] = y ;
288   specialup_seq[winIdx] = sequence_number ;
289   glutPostRedisplay () ;
290 }
291
292 static void 
293 Joystick( unsigned int a, int b, int c, int d)  /* Need meaningful names */
294 {
295   int winIdx;
296   int window = getWindowAndIdx(&winIdx);
297   printf ( "%6d Window %d Joystick Callback:  %d %d %d %d\n",
298             ++sequence_number, window, a, b, c, d ) ;
299   joystick_called[winIdx] = 1 ;
300   joystick_a[winIdx] = a ;
301   joystick_b[winIdx] = b ;
302   joystick_c[winIdx] = c ;
303   joystick_d[winIdx] = d ;
304   joystick_seq[winIdx] = sequence_number ;
305   glutPostRedisplay () ;
306 }
307
308 static void 
309 Mouse(int button, int updown, int x, int y)
310 {
311   int winIdx;
312   int window = getWindowAndIdx(&winIdx);
313   printf ( "%6d Window %d Mouse Click Callback:  %d %d %d %d\n",
314             ++sequence_number, window, button, updown, x, y ) ;
315   mouse_called[winIdx] = 1 ;
316   mouse_button[winIdx] = button ;
317   mouse_updown[winIdx] = updown ;
318   mouse_x[winIdx] = x ;
319   mouse_y[winIdx] = y ;
320   mouse_seq[winIdx] = sequence_number ;
321   glutPostRedisplay () ;
322 }
323
324 static void 
325 MouseWheel(int wheel_number, int direction, int x, int y)
326 {
327   int winIdx;
328   int window = getWindowAndIdx(&winIdx);
329   printf ( "%6d Window %d Mouse Wheel Callback:  %d %d %d %d\n",
330             ++sequence_number, window, wheel_number, direction, x, y ) ;
331   mousewheel_called[winIdx] = 1 ;
332   mousewheel_number[winIdx] = wheel_number ;
333   mousewheel_direction[winIdx] = direction ;
334   mousewheel_x[winIdx] = x ;
335   mousewheel_y[winIdx] = y ;
336   mousewheel_seq[winIdx] = sequence_number ;
337   glutPostRedisplay () ;
338 }
339
340 static void 
341 Motion(int x, int y)
342 {
343   int winIdx;
344   int window = getWindowAndIdx(&winIdx);
345   printf ( "%6d Window %d Mouse Motion Callback:  %d %d\n",
346             ++sequence_number, window, x, y ) ;
347   motion_called[winIdx] = 1 ;
348   motion_x[winIdx] = x ;
349   motion_y[winIdx] = y ;
350   motion_seq[winIdx] = sequence_number ;
351   glutPostRedisplay () ;
352 }
353
354 static void 
355 PassiveMotion(int x, int y)
356 {
357   int winIdx;
358   int window = getWindowAndIdx(&winIdx);
359   printf ( "%6d Window %d Mouse Passive Motion Callback:  %d %d\n",
360             ++sequence_number, window, x, y ) ;
361   passivemotion_called[winIdx] = 1 ;
362   passivemotion_x[winIdx] = x ;
363   passivemotion_y[winIdx] = y ;
364   passivemotion_seq[winIdx] = sequence_number ;
365   glutPostRedisplay () ;
366 }
367
368 static void 
369 Entry(int state)
370 {
371   int window = getWindowAndIdx(NULL);
372   printf ( "%6d Window %d Entry Callback:  %d\n",
373             ++sequence_number, window, state ) ;
374   glutPostRedisplay () ;
375 }
376
377 static void 
378 Close(void)
379 {
380   int window = getWindowAndIdx(NULL);
381   printf ( "%6d Window %d Close Callback\n",
382             ++sequence_number, window ) ;
383 }
384
385 static void 
386 OverlayDisplay(void)
387 {
388   int window = getWindowAndIdx(NULL);
389   printf ( "%6d Window %d OverlayDisplay Callback\n",
390             ++sequence_number, window ) ;
391   glutPostRedisplay () ;
392 }
393
394 static void 
395 WindowStatus(int state)
396 {
397   int window = getWindowAndIdx(NULL);
398   printf ( "%6d Window %d WindowStatus Callback:  %d\n",
399             ++sequence_number, window, state ) ;
400   glutPostRedisplay () ;
401 }
402
403 static void 
404 SpaceMotion(int x, int y, int z)
405 {
406   int window = getWindowAndIdx(NULL);
407   printf ( "%6d Window %d SpaceMotion Callback:  %d %d %d\n",
408             ++sequence_number, window, x, y, z ) ;
409   glutPostRedisplay () ;
410 }
411
412 static void 
413 SpaceRotation(int x, int y, int z)
414 {
415   int window = getWindowAndIdx(NULL);
416   printf ( "%6d Window %d SpaceRotation Callback:  %d %d %d\n",
417             ++sequence_number, window, x, y, z ) ;
418   glutPostRedisplay () ;
419 }
420
421 static void 
422 SpaceButton(int button, int updown)
423 {
424   int window = getWindowAndIdx(NULL);
425   printf ( "%6d Window %d SpaceButton Callback:  %d %d\n",
426             ++sequence_number, window, button, updown ) ;
427   glutPostRedisplay () ;
428 }
429
430 static void 
431 Dials(int x, int y)
432 {
433   int window = getWindowAndIdx(NULL);
434   printf ( "%6d Window %d Dials Callback:  %d %d\n",
435             ++sequence_number, window, x, y ) ;
436   glutPostRedisplay () ;
437 }
438
439 static void 
440 ButtonBox(int button, int updown)
441 {
442   int window = getWindowAndIdx(NULL);
443   printf ( "%6d Window %d ButtonBox Callback:  %d %d\n",
444             ++sequence_number, window, button, updown ) ;
445   glutPostRedisplay () ;
446 }
447
448 static void 
449 TabletMotion(int x, int y)
450 {
451   int window = getWindowAndIdx(NULL);
452   printf ( "%6d Window %d TabletMotion Callback:  %d %d\n",
453             ++sequence_number, window, x, y ) ;
454   glutPostRedisplay () ;
455 }
456
457 static void 
458 TabletButton(int button, int updown, int x, int y)
459 {
460   int window = getWindowAndIdx(NULL);
461   printf ( "%6d Window %d TabletButton Callback:  %d %d %d %d\n",
462             ++sequence_number, window, button, updown, x, y ) ;
463   glutPostRedisplay () ;
464 }
465
466 static void
467 MenuCallback ( int value )
468 {
469   int menu = glutGetMenu();
470   int window = getWindowAndIdx(NULL);
471   printf( "%6d Menu %d MenuCallback for menu opened in Window %d - value is %d\n",
472           ++sequence_number, menu, window, value );
473 }
474
475 static void 
476 MenuDestroy( void )
477 {
478   int menu = glutGetMenu();
479   menudestroy_called = 1 ;
480   printf ( "%6d Menu %d MenuDestroy Callback\n",
481             ++sequence_number, menu ) ;
482 }
483
484 static void 
485 MenuStatus( int status, int x, int y )
486 {
487   /* Menu and window for which this event is triggered are current when the callback is called */
488   int menu = glutGetMenu();
489   int window = getWindowAndIdx(NULL);
490   menustatus_called = 1 ;
491   printf ( "%6d Menu %d MenuStatus Callback in Window %d:  %d %d %d\n",
492             ++sequence_number, menu, window, status, x, y ) ;
493   glutPostRedisplay () ;
494 }
495
496
497 static void 
498 MenuState( int status )
499 {
500   /* Menu and window for which this event is triggered are current when the callback is called */
501   int menu = glutGetMenu();
502   int window = getWindowAndIdx(NULL);
503   menustate_called = 1 ;
504   printf ( "%6d Menu %d MenuState Callback in Window %d:  %d\n",
505             ++sequence_number, menu, window, status) ;
506   glutPostRedisplay () ;
507 }
508
509 static void Idle ( void )
510 {
511   ++sequence_number ;
512 }
513
514 int 
515 main(int argc, char *argv[])
516 {
517   char dummy_string[STRING_LENGTH];
518
519   int menuID, subMenuA, subMenuB;
520
521   glutInitWarningFunc(Warning);
522   glutInitErrorFunc(Error);
523   glutInitWindowSize(500, 250);
524   glutInitWindowPosition ( 140, 140 );
525   glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE );
526   glutInit(&argc, argv);
527   glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_CONTINUE_EXECUTION);
528
529   /* Set other global callback (global as in not associated with any specific menu or window) */
530   glutIdleFunc ( Idle );
531   glutMenuStatusFunc ( MenuStatus );
532   glutMenuStateFunc  ( MenuState ); /* Note that glutMenuStatusFunc is an enhanced version of the deprecated glutMenuStateFunc. */
533
534   windows[0] = glutCreateWindow( "Callback Demo" );
535   printf ( "Creating window %d as 'Callback Demo'\n", windows[0] ) ;
536
537   glClearColor(1.0, 1.0, 1.0, 1.0);
538
539   /* callbacks and settings specific to this window */
540   glutDisplayFunc( Display );
541   glutReshapeFunc( Reshape );
542   glutKeyboardFunc( Key );
543   glutSpecialFunc( Special );
544   glutVisibilityFunc( Visibility );
545   glutKeyboardUpFunc( KeyUp );
546   glutSpecialUpFunc( SpecialUp );
547   glutJoystickFunc( Joystick, 100 );
548   glutMouseFunc ( Mouse ) ;
549   glutMouseWheelFunc ( MouseWheel ) ;
550   glutMotionFunc ( Motion ) ;
551   glutPassiveMotionFunc ( PassiveMotion ) ;
552   glutEntryFunc ( Entry ) ;
553   glutCloseFunc ( Close ) ;
554   glutOverlayDisplayFunc ( OverlayDisplay ) ;
555   glutWindowStatusFunc ( WindowStatus ) ;
556   glutSpaceballMotionFunc ( SpaceMotion ) ;
557   glutSpaceballRotateFunc ( SpaceRotation ) ;
558   glutSpaceballButtonFunc ( SpaceButton ) ;
559   glutButtonBoxFunc ( ButtonBox ) ;
560   glutDialsFunc ( Dials ) ;
561   glutTabletMotionFunc ( TabletMotion ) ;
562   glutTabletButtonFunc ( TabletButton ) ;
563   glutSetKeyRepeat(GLUT_KEY_REPEAT_OFF) ;
564
565   subMenuA = glutCreateMenu( MenuCallback );
566   glutAddMenuEntry( "Sub menu A1 (01)", 11 );
567   glutAddMenuEntry( "Sub menu A2 (02)", 12 );
568   glutAddMenuEntry( "Sub menu A3 (03)", 13 );
569   glutMenuDestroyFunc ( MenuDestroy );  /* callback specific to this menu */
570
571   subMenuB = glutCreateMenu( MenuCallback );
572   glutAddMenuEntry( "Sub menu B1 (04)", 14 );
573   glutAddMenuEntry( "Sub menu B2 (05)", 15 );
574   glutAddMenuEntry( "Sub menu B3 (06)", 16 );
575   glutAddSubMenu( "Going to sub menu A", subMenuA );
576   glutMenuDestroyFunc ( MenuDestroy );  /* callback specific to this menu */
577
578   menuID = glutCreateMenu( MenuCallback );
579   glutAddMenuEntry( "Entry one",   21 );
580   glutAddMenuEntry( "Entry two",   22 );
581   glutAddMenuEntry( "Entry three", 23 );
582   glutAddMenuEntry( "Entry four",  24 );
583   glutAddMenuEntry( "Entry five",  25 );
584   glutAddSubMenu( "Enter sub menu A", subMenuA );
585   glutAddSubMenu( "Enter sub menu B", subMenuB );
586   glutMenuDestroyFunc ( MenuDestroy );  /* callback specific to this menu */
587
588   glutAttachMenu( GLUT_LEFT_BUTTON );
589
590   glutInitWindowPosition ( 140+500+2*glutGet(GLUT_WINDOW_BORDER_WIDTH), 140 );
591   /* Position second window right next to the first */
592   windows[1] = glutCreateWindow( "Second Window" );
593   printf ( "Creating window %d as 'Second Window'\n", windows[1] ) ;
594
595   glClearColor(1.0, 1.0, 1.0, 1.0);
596
597   /* callbacks and settings specific to this window */
598   glutDisplayFunc( Display );
599   glutReshapeFunc( Reshape );
600   glutKeyboardFunc( Key );
601   glutSpecialFunc( Special );
602   glutVisibilityFunc( Visibility );
603   glutKeyboardUpFunc( KeyUp );
604   glutSpecialUpFunc( SpecialUp );
605   /*  glutJoystickFunc( Joystick, 100 ); */
606   glutMouseFunc ( Mouse ) ;
607   glutMouseWheelFunc ( MouseWheel ) ;
608   glutMotionFunc ( Motion ) ;
609   glutPassiveMotionFunc ( PassiveMotion ) ;
610   glutEntryFunc ( Entry ) ;
611   glutCloseFunc ( Close ) ;
612   glutOverlayDisplayFunc ( OverlayDisplay ) ;
613   glutWindowStatusFunc ( WindowStatus ) ;
614   glutSpaceballMotionFunc ( SpaceMotion ) ;
615   glutSpaceballRotateFunc ( SpaceRotation ) ;
616   glutSpaceballButtonFunc ( SpaceButton ) ;
617   glutButtonBoxFunc ( ButtonBox ) ;
618   glutDialsFunc ( Dials ) ;
619   glutTabletMotionFunc ( TabletMotion ) ;
620   glutTabletButtonFunc ( TabletButton ) ;
621   glutSetKeyRepeat(GLUT_KEY_REPEAT_OFF) ;
622
623   glutSetMenu(subMenuB);
624   glutAttachMenu( GLUT_RIGHT_BUTTON );
625
626
627   printf ( "Please enter something to continue: " );
628   fgets ( dummy_string, STRING_LENGTH, stdin );
629
630   glutMainLoop();
631
632   printf ( "Back from the 'freeglut' main loop\n" ) ;
633
634   return EXIT_SUCCESS;
635 }