3 * Program to invoke all the callbacks that "freeglut" supports
7 #include <GL/freeglut.h>
13 static int sequence_number = 0 ;
15 #define CALLBACKMAKER_N_WINDOWS 4
16 int windows[CALLBACKMAKER_N_WINDOWS] = {0};
18 /* define status vars showing whether given callback has been called for given window */
19 #define CALLBACK_CALLED_VAR(name) int name##_called[CALLBACKMAKER_N_WINDOWS] = {0}
20 #define CALLBACK_0V(name) int name##_seq[CALLBACKMAKER_N_WINDOWS] = {-1}; CALLBACK_CALLED_VAR(name)
21 #define CALLBACK_1V(name,field) int name##_##field[CALLBACKMAKER_N_WINDOWS] = {-1}; CALLBACK_0V(name)
22 #define CALLBACK_2V(name,field1,field2) int name##_##field2[CALLBACKMAKER_N_WINDOWS] = {-1}; CALLBACK_1V(name,field1)
23 #define CALLBACK_3V(name,field1,field2,field3) int name##_##field3[CALLBACKMAKER_N_WINDOWS] = {-1}; CALLBACK_2V(name,field1,field2)
24 #define CALLBACK_4V(name,field1,field2,field3,field4) int name##_##field4[CALLBACKMAKER_N_WINDOWS] = {-1}; CALLBACK_3V(name,field1,field2,field3)
25 #define CALLBACK_5V(name,field1,field2,field3,field4,field5) int name##_##field5[CALLBACKMAKER_N_WINDOWS] = {-1}; CALLBACK_4V(name,field1,field2,field3,field4)
26 CALLBACK_2V(reshape,width,height);
27 CALLBACK_2V(position,top,left);
28 CALLBACK_1V(visibility,vis);
29 CALLBACK_1V(windowStatus,state);
30 CALLBACK_4V(key,key,x,y,mod);
31 CALLBACK_4V(keyup,key,x,y,mod);
32 CALLBACK_4V(special,key,x,y,mod);
33 CALLBACK_4V(specialup,key,x,y,mod);
34 CALLBACK_4V(joystick,a,b,c,d);
35 CALLBACK_5V(mouse,button,updown,x,y,mod);
36 CALLBACK_5V(mousewheel,number,direction,x,y,mod);
37 CALLBACK_3V(motion,x,y,mod);
38 CALLBACK_3V(passivemotion,x,y,mod);
39 CALLBACK_1V(entry,state);
41 /* menudestroy is registered on each menu, not a window */
42 int menudestroy_called = 0;
43 /* menustatus and menustate are global callbacks, set for all menus at the same time */
44 int menustatus_called = 0;
45 int menustate_called = 0;
47 #define STRING_LENGTH 10
50 bitmapPrintf (const char *fmt, ...)
56 #if defined(WIN32) && !defined(__CYGWIN__)
57 (void) _vsnprintf (buf, sizeof(buf), fmt, args);
59 (void) vsnprintf (buf, sizeof(buf), fmt, args);
62 glutBitmapString ( GLUT_BITMAP_HELVETICA_12, (unsigned char*)buf ) ;
66 getWindowAndIdx(int *winIdx)
68 int window = glutGetWindow();
71 (*winIdx) = window==windows[0] ? 0 :
72 window==windows[1] ? 1 :
73 window==windows[2] ? 2 : 3;
79 Mod2Text(int mods, char *text)
81 if (mods&GLUT_ACTIVE_CTRL)
83 if (mods&GLUT_ACTIVE_SHIFT)
86 strcat(text,"+SHIFT");
90 if (mods&GLUT_ACTIVE_ALT)
106 int window = getWindowAndIdx(&winIdx);
107 glClear ( GL_COLOR_BUFFER_BIT );
109 glDisable ( GL_DEPTH_TEST );
110 glMatrixMode ( GL_PROJECTION );
113 glOrtho(0, glutGet ( GLUT_WINDOW_WIDTH ),
114 0, glutGet ( GLUT_WINDOW_HEIGHT ), -1, 1 );
115 glMatrixMode ( GL_MODELVIEW );
118 glColor3ub ( 0, 0, 0 );
119 glRasterPos2i ( 10, glutGet ( GLUT_WINDOW_HEIGHT ) - 20 ); /* 10pt margin above 10pt letters */
121 if ( entry_called[winIdx] )
123 bitmapPrintf ( "Entry %d: %d\n", entry_seq[winIdx], entry_state[winIdx] );
126 if ( visibility_called[winIdx] )
128 bitmapPrintf ( "Visibility %d: %d\n", visibility_seq[winIdx], visibility_vis[winIdx] );
131 if ( windowStatus_called[winIdx] )
133 bitmapPrintf ( "WindowStatus %d: %d\n", windowStatus_seq[winIdx], windowStatus_state[winIdx] );
136 if ( reshape_called[winIdx] )
138 bitmapPrintf ( "Reshape %d: %d %d\n", reshape_seq[winIdx], reshape_width[winIdx], reshape_height[winIdx] );
141 if ( position_called[winIdx] )
143 bitmapPrintf ( "Position %d: %d %d\n", position_seq[winIdx], position_left[winIdx], position_top[winIdx] );
146 if ( key_called[winIdx] )
149 Mod2Text(key_mod[winIdx],mods);
150 bitmapPrintf ( "Key %d: %d(%c) %d %d (mod: %s)\n", key_seq[winIdx], key_key[winIdx], key_key[winIdx], key_x[winIdx], key_y[winIdx], mods );
153 if ( keyup_called[winIdx] )
156 Mod2Text(keyup_mod[winIdx],mods);
157 bitmapPrintf ( "Key Up %d: %d(%c) %d %d (mod: %s)\n", keyup_seq[winIdx], keyup_key[winIdx], keyup_key[winIdx], keyup_x[winIdx], keyup_y[winIdx], mods );
160 if ( special_called[winIdx] )
163 Mod2Text(special_mod[winIdx],mods);
164 bitmapPrintf ( "Special %d: %d(%c) %d %d (mod: %s)\n", special_seq[winIdx], special_key[winIdx], special_key[winIdx], special_x[winIdx], special_y[winIdx], mods );
167 if ( specialup_called[winIdx] )
170 Mod2Text(specialup_mod[winIdx],mods);
171 bitmapPrintf ( "Special Up %d: %d(%c) %d %d (mod: %s)\n", specialup_seq[winIdx], specialup_key[winIdx], specialup_key[winIdx], specialup_x[winIdx], specialup_y[winIdx], mods );
174 if ( joystick_called[winIdx] )
176 bitmapPrintf ( "Joystick %d: %d %d %d %d\n", joystick_seq[winIdx], joystick_a[winIdx], joystick_b[winIdx], joystick_c[winIdx], joystick_d[winIdx] );
179 if ( mouse_called[winIdx] )
182 Mod2Text(mouse_mod[winIdx],mods);
183 bitmapPrintf ( "Mouse %d: %d %d %d %d (mod: %s)\n", mouse_seq[winIdx], mouse_button[winIdx], mouse_updown[winIdx], mouse_x[winIdx], mouse_y[winIdx], mods );
186 if ( mousewheel_called[winIdx] )
189 Mod2Text(mousewheel_mod[winIdx],mods);
190 bitmapPrintf ( "Mouse Wheel %d: %d %d %d %d (mod: %s)\n", mousewheel_seq[winIdx], mousewheel_number[winIdx], mousewheel_direction[winIdx], mousewheel_x[winIdx], mousewheel_y[winIdx], mods );
193 if ( motion_called[winIdx] )
196 Mod2Text(motion_mod[winIdx],mods);
197 bitmapPrintf ( "Motion %d: %d %d (mod: %s)\n", motion_seq[winIdx], motion_x[winIdx], motion_y[winIdx], mods );
200 if ( passivemotion_called[winIdx] )
203 Mod2Text(passivemotion_mod[winIdx],mods);
204 bitmapPrintf ( "Passive Motion %d: %d %d (mod: %s)\n", passivemotion_seq[winIdx], passivemotion_x[winIdx], passivemotion_y[winIdx], mods );
207 glMatrixMode ( GL_PROJECTION );
209 glMatrixMode ( GL_MODELVIEW );
211 glEnable ( GL_DEPTH_TEST );
213 printf ( "%6d Window %d Display Callback\n",
214 ++sequence_number, window ) ;
219 Warning(const char *fmt, va_list ap)
221 printf("%6d Warning callback:\n",++sequence_number);
223 /* print warning message */
228 Error(const char *fmt, va_list ap)
230 char dummy_string[STRING_LENGTH];
231 printf("%6d Error callback:\n",++sequence_number);
233 /* print warning message */
237 /* terminate program, after pause for input so user can see */
238 printf ( "Please enter something to exit: " );
239 fgets ( dummy_string, STRING_LENGTH, stdin );
241 /* Call exit directly as freeglut is messed
242 * up internally when an error is called.
248 Reshape(int width, int height)
251 int window = getWindowAndIdx(&winIdx);
252 printf ( "%6d Window %d Reshape Callback: %d %d\n",
253 ++sequence_number, window, width, height ) ;
254 reshape_called[winIdx] = 1 ;
255 reshape_width[winIdx] = width ;
256 reshape_height[winIdx] = height ;
257 reshape_seq[winIdx] = sequence_number ;
258 glViewport(0,0,width,height);
259 glutPostRedisplay () ;
263 Position(int left, int top)
266 int window = getWindowAndIdx(&winIdx);
267 printf ( "%6d Window %d Position Callback: %d %d\n",
268 ++sequence_number, window, left, top ) ;
269 position_called[winIdx] = 1 ;
270 position_left[winIdx] = left ;
271 position_top[winIdx] = top ;
272 position_seq[winIdx] = sequence_number ;
273 glutPostRedisplay () ;
277 Key(unsigned char key, int x, int y)
280 int window = getWindowAndIdx(&winIdx);
281 printf ( "%6d Window %d Keyboard Callback: %d %d %d\n",
282 ++sequence_number, window, key, x, y ) ;
283 key_called[winIdx] = 1 ;
284 key_key[winIdx] = key ;
287 key_seq[winIdx] = sequence_number ;
288 key_mod[winIdx] = glutGetModifiers() ;
289 glutPostRedisplay () ;
293 KeyUp(unsigned char key, int x, int y)
296 int window = getWindowAndIdx(&winIdx);
297 printf ( "%6d Window %d Key Release Callback: %d %d %d\n",
298 ++sequence_number, window, key, x, y ) ;
299 keyup_called[winIdx] = 1 ;
300 keyup_key[winIdx] = key ;
301 keyup_x[winIdx] = x ;
302 keyup_y[winIdx] = y ;
303 keyup_seq[winIdx] = sequence_number ;
304 keyup_mod[winIdx] = glutGetModifiers() ;
305 glutPostRedisplay () ;
309 Special(int key, int x, int y)
312 int window = getWindowAndIdx(&winIdx);
313 printf ( "%6d Window %d Special Key Callback: %d %d %d\n",
314 ++sequence_number, window, key, x, y ) ;
315 special_called[winIdx] = 1 ;
316 special_key[winIdx] = key ;
317 special_x[winIdx] = x ;
318 special_y[winIdx] = y ;
319 special_seq[winIdx] = sequence_number ;
320 special_mod[winIdx] = glutGetModifiers() ;
321 glutPostRedisplay () ;
325 SpecialUp(int key, int x, int y)
328 int window = getWindowAndIdx(&winIdx);
329 printf ( "%6d Window %d Special Key Release Callback: %d %d %d\n",
330 ++sequence_number, window, key, x, y ) ;
331 specialup_called[winIdx] = 1 ;
332 specialup_key[winIdx] = key ;
333 specialup_x[winIdx] = x ;
334 specialup_y[winIdx] = y ;
335 specialup_seq[winIdx] = sequence_number ;
336 specialup_mod[winIdx] = glutGetModifiers() ;
337 glutPostRedisplay () ;
341 Joystick( unsigned int a, int b, int c, int d) /* Need meaningful names */
344 int window = getWindowAndIdx(&winIdx);
345 printf ( "%6d Window %d Joystick Callback: %d %d %d %d\n",
346 ++sequence_number, window, a, b, c, d ) ;
347 joystick_called[winIdx] = 1 ;
348 joystick_a[winIdx] = a ;
349 joystick_b[winIdx] = b ;
350 joystick_c[winIdx] = c ;
351 joystick_d[winIdx] = d ;
352 joystick_seq[winIdx] = sequence_number ;
353 glutPostRedisplay () ;
357 Mouse(int button, int updown, int x, int y)
360 int window = getWindowAndIdx(&winIdx);
361 printf ( "%6d Window %d Mouse Click Callback: %d %d %d %d\n",
362 ++sequence_number, window, button, updown, x, y ) ;
363 mouse_called[winIdx] = 1 ;
364 mouse_button[winIdx] = button ;
365 mouse_updown[winIdx] = updown ;
366 mouse_x[winIdx] = x ;
367 mouse_y[winIdx] = y ;
368 mouse_seq[winIdx] = sequence_number ;
369 mouse_mod[winIdx] = glutGetModifiers() ;
370 glutPostRedisplay () ;
374 MouseWheel(int wheel_number, int direction, int x, int y)
377 int window = getWindowAndIdx(&winIdx);
378 printf ( "%6d Window %d Mouse Wheel Callback: %d %d %d %d\n",
379 ++sequence_number, window, wheel_number, direction, x, y ) ;
380 mousewheel_called[winIdx] = 1 ;
381 mousewheel_number[winIdx] = wheel_number ;
382 mousewheel_direction[winIdx] = direction ;
383 mousewheel_x[winIdx] = x ;
384 mousewheel_y[winIdx] = y ;
385 mousewheel_seq[winIdx] = sequence_number ;
386 mousewheel_mod[winIdx] = glutGetModifiers() ;
387 glutPostRedisplay () ;
394 int window = getWindowAndIdx(&winIdx);
395 printf ( "%6d Window %d Mouse Motion Callback: %d %d\n",
396 ++sequence_number, window, x, y ) ;
397 motion_called[winIdx] = 1 ;
398 motion_x[winIdx] = x ;
399 motion_y[winIdx] = y ;
400 motion_seq[winIdx] = sequence_number ;
401 motion_mod[winIdx] = glutGetModifiers() ;
402 glutPostRedisplay () ;
406 PassiveMotion(int x, int y)
409 int window = getWindowAndIdx(&winIdx);
410 printf ( "%6d Window %d Mouse Passive Motion Callback: %d %d\n",
411 ++sequence_number, window, x, y ) ;
412 passivemotion_called[winIdx] = 1 ;
413 passivemotion_x[winIdx] = x ;
414 passivemotion_y[winIdx] = y ;
415 passivemotion_seq[winIdx] = sequence_number ;
416 passivemotion_mod[winIdx] = glutGetModifiers() ;
417 glutPostRedisplay () ;
424 int window = getWindowAndIdx(&winIdx);
425 printf ( "%6d Window %d Entry Callback: %d\n",
426 ++sequence_number, window, state ) ;
427 entry_called[winIdx] = 1 ;
428 entry_seq[winIdx] = sequence_number;
429 entry_state[winIdx] = state;
430 glutPostRedisplay () ;
436 int window = getWindowAndIdx(NULL);
437 printf ( "%6d Window %d Close Callback\n",
438 ++sequence_number, window ) ;
444 int window = getWindowAndIdx(NULL);
445 printf ( "%6d Window %d OverlayDisplay Callback\n",
446 ++sequence_number, window ) ;
447 glutPostRedisplay () ;
454 int window = getWindowAndIdx(&winIdx);
455 printf ( "%6d Window %d Visibility Callback: %d\n",
456 ++sequence_number, window, vis ) ;
457 visibility_called[winIdx] = 1 ;
458 visibility_vis[winIdx] = vis ;
459 visibility_seq[winIdx] = sequence_number ;
460 glutPostRedisplay () ;
464 WindowStatus(int state)
467 int window = getWindowAndIdx(&winIdx);
468 printf ( "%6d Window %d WindowStatus Callback: %d\n",
469 ++sequence_number, window, state ) ;
470 windowStatus_called[winIdx] = 1 ;
471 windowStatus_state[winIdx] = state ;
472 windowStatus_seq[winIdx] = sequence_number ;
473 glutPostRedisplay () ;
477 SpaceMotion(int x, int y, int z)
479 int window = getWindowAndIdx(NULL);
480 printf ( "%6d Window %d SpaceMotion Callback: %d %d %d\n",
481 ++sequence_number, window, x, y, z ) ;
482 glutPostRedisplay () ;
486 SpaceRotation(int x, int y, int z)
488 int window = getWindowAndIdx(NULL);
489 printf ( "%6d Window %d SpaceRotation Callback: %d %d %d\n",
490 ++sequence_number, window, x, y, z ) ;
491 glutPostRedisplay () ;
495 SpaceButton(int button, int updown)
497 int window = getWindowAndIdx(NULL);
498 printf ( "%6d Window %d SpaceButton Callback: %d %d\n",
499 ++sequence_number, window, button, updown ) ;
500 glutPostRedisplay () ;
506 int window = getWindowAndIdx(NULL);
507 printf ( "%6d Window %d Dials Callback: %d %d\n",
508 ++sequence_number, window, x, y ) ;
509 glutPostRedisplay () ;
513 ButtonBox(int button, int updown)
515 int window = getWindowAndIdx(NULL);
516 printf ( "%6d Window %d ButtonBox Callback: %d %d\n",
517 ++sequence_number, window, button, updown ) ;
518 glutPostRedisplay () ;
522 TabletMotion(int x, int y)
524 int window = getWindowAndIdx(NULL);
525 printf ( "%6d Window %d TabletMotion Callback: %d %d\n",
526 ++sequence_number, window, x, y ) ;
527 glutPostRedisplay () ;
531 TabletButton(int button, int updown, int x, int y)
533 int window = getWindowAndIdx(NULL);
534 printf ( "%6d Window %d TabletButton Callback: %d %d %d %d\n",
535 ++sequence_number, window, button, updown, x, y ) ;
536 glutPostRedisplay () ;
540 MenuCallback ( int value )
542 int menu = glutGetMenu();
543 int window = getWindowAndIdx(NULL);
544 printf( "%6d Menu %d MenuCallback for menu opened in Window %d - value is %d\n",
545 ++sequence_number, menu, window, value );
551 int menu = glutGetMenu();
552 menudestroy_called = 1 ;
553 printf ( "%6d Menu %d MenuDestroy Callback\n",
554 ++sequence_number, menu ) ;
558 MenuStatus( int status, int x, int y )
560 /* Menu and window for which this event is triggered are current when the callback is called */
561 int menu = glutGetMenu();
562 int window = getWindowAndIdx(NULL);
563 menustatus_called = 1 ;
564 printf ( "%6d Menu %d MenuStatus Callback in Window %d: %d %d %d\n",
565 ++sequence_number, menu, window, status, x, y ) ;
566 glutPostRedisplay () ;
571 MenuState( int status )
573 /* Menu and window for which this event is triggered are current when the callback is called */
574 int menu = glutGetMenu();
575 int window = getWindowAndIdx(NULL);
576 menustate_called = 1 ;
577 printf ( "%6d Menu %d MenuState Callback in Window %d: %d\n",
578 ++sequence_number, menu, window, status) ;
579 glutPostRedisplay () ;
582 static void Idle ( void )
587 static void SetWindowCallbacks( int first )
589 /* All these callbacks are set for only the current window */
590 glutDisplayFunc( Display );
591 glutReshapeFunc( Reshape );
592 glutPositionFunc( Position );
593 glutKeyboardFunc( Key );
594 glutSpecialFunc( Special );
595 glutKeyboardUpFunc( KeyUp );
596 glutSpecialUpFunc( SpecialUp );
598 glutJoystickFunc( Joystick, 100 );
599 glutMouseFunc ( Mouse ) ;
600 glutMouseWheelFunc ( MouseWheel ) ;
601 glutMotionFunc ( Motion ) ;
602 glutPassiveMotionFunc ( PassiveMotion ) ;
603 glutEntryFunc ( Entry ) ;
604 glutCloseFunc ( Close ) ;
605 glutOverlayDisplayFunc ( OverlayDisplay ) ;
606 glutSpaceballMotionFunc ( SpaceMotion ) ;
607 glutSpaceballRotateFunc ( SpaceRotation ) ;
608 glutSpaceballButtonFunc ( SpaceButton ) ;
609 glutButtonBoxFunc ( ButtonBox ) ;
610 glutDialsFunc ( Dials ) ;
611 glutTabletMotionFunc ( TabletMotion ) ;
612 glutTabletButtonFunc ( TabletButton ) ;
613 /* glutVisibilityFunc is deprecated in favor of glutWindowStatusFunc, which provides more detail.
614 * Setting one of these overwrites the other (see docs).
616 glutVisibilityFunc ( Visibility ); /* This will thus never be called, as glutWindowStatusFunc is set afterwards */
617 glutWindowStatusFunc ( WindowStatus ) ;
621 main(int argc, char *argv[])
623 char dummy_string[STRING_LENGTH];
625 int menuID, subMenuA, subMenuB;
627 glutInitWarningFunc(Warning);
628 glutInitErrorFunc(Error);
629 glutInitWindowSize(500, 250);
630 glutInitWindowPosition ( 140, 140 );
631 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE );
632 glutInit(&argc, argv);
633 /* global setting: mainloop does not return when a window is closed, only returns when all windows are closed */
634 glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_CONTINUE_EXECUTION);
635 /* global setting: repeated keys generating by keeping the key pressed down are passed on to the keyboard callback */
636 /* There are two functions to control this behavior, glutSetKeyRepeat to set it globally, and glutIgnoreKeyRepeat to set it per window.
637 * These two interact however. If key repeat is globally switched off (glutSetKeyRepeat(GLUT_KEY_REPEAT_OFF)), it cannot be overridden
638 * (switched back on) for a specific window with glutIgnoreKeyRepeat. However, if key repeat is globally switched on
639 * (glutSetKeyRepeat(GLUT_KEY_REPEAT_ON)), it can be overridden (switched off) with glutIgnoreKeyRepeat on a per-window basis. That is
640 * what we demonstrate here.
642 glutSetKeyRepeat(GLUT_KEY_REPEAT_ON);
644 /* Set other global callback (global as in not associated with any specific menu or window) */
645 glutIdleFunc ( Idle );
646 glutMenuStatusFunc ( MenuStatus );
647 glutMenuStateFunc ( MenuState ); /* Note that glutMenuStatusFunc is an enhanced version of the deprecated glutMenuStateFunc. */
650 /* Open first window */
651 windows[0] = glutCreateWindow( "Callback Demo" );
652 printf ( "Creating window %d as 'Callback Demo'\n", windows[0] ) ;
654 glClearColor(1.0, 1.0, 1.0, 1.0);
656 /* callbacks, settings and menus for this window */
657 SetWindowCallbacks( 1 );
658 glutIgnoreKeyRepeat(GL_TRUE);
659 glutSetIconTitle("Icon Test - Callback Demo");
661 subMenuA = glutCreateMenu( MenuCallback );
662 glutAddMenuEntry( "Sub menu A1 (01)", 11 );
663 glutAddMenuEntry( "Sub menu A2 (02)", 12 );
664 glutAddMenuEntry( "Sub menu A3 (03)", 13 );
665 glutMenuDestroyFunc ( MenuDestroy ); /* callback specific to this menu */
666 /* Change font for this menu */
667 glutSetMenuFont(subMenuA, GLUT_BITMAP_HELVETICA_12);
669 subMenuB = glutCreateMenu( MenuCallback );
670 glutAddMenuEntry( "Sub menu B1 (04)", 14 );
671 glutAddMenuEntry( "Sub menu B2 (05)", 15 );
672 glutAddMenuEntry( "Sub menu B3 (06)", 16 );
673 glutAddSubMenu( "Going to sub menu A", subMenuA );
674 glutMenuDestroyFunc ( MenuDestroy ); /* callback specific to this menu */
675 glutSetMenuFont(subMenuB, GLUT_BITMAP_9_BY_15);
677 menuID = glutCreateMenu( MenuCallback );
678 glutAddMenuEntry( "Entry one", 21 );
679 glutAddMenuEntry( "Entry two", 22 );
680 glutAddMenuEntry( "Entry three", 23 );
681 glutAddMenuEntry( "Entry four", 24 );
682 glutAddMenuEntry( "Entry five", 25 );
683 glutAddSubMenu( "Enter sub menu A", subMenuA );
684 glutAddSubMenu( "Enter sub menu B", subMenuB );
685 glutMenuDestroyFunc ( MenuDestroy ); /* callback specific to this menu */
687 glutAttachMenu( GLUT_LEFT_BUTTON );
690 /* Position second window right next to the first */
691 glutInitWindowPosition ( 140+500+2*glutGet(GLUT_WINDOW_BORDER_WIDTH), 140 );
692 glutInitWindowSize(600, 600);
693 windows[1] = glutCreateWindow( "Second Window" );
694 printf ( "Creating window %d as 'Second Window'\n", windows[1] ) ;
696 glClearColor(1.0, 1.0, 1.0, 1.0);
698 /* callbacks, settings and menus for this window */
699 SetWindowCallbacks( 0 );
700 glutIgnoreKeyRepeat(GL_TRUE);
702 glutSetMenu(subMenuB);
703 glutAttachMenu( GLUT_RIGHT_BUTTON );
706 /* position a third window as a subwindow of the second */
707 windows[2] = glutCreateSubWindow(windows[1],0,300,600,300);
708 printf ( "Creating window %d as subwindow to 'Second Window'\n", windows[2] ) ;
710 glClearColor(0.7f, 0.7f, 0.7f, 1.0);
712 /* callbacks, settings and menus for this window */
713 SetWindowCallbacks( 0 );
714 glutSetCursor(GLUT_CURSOR_CROSSHAIR); /* Cursors are per window */
716 glutSetMenu(subMenuA);
717 glutAttachMenu( GLUT_RIGHT_BUTTON );
720 /* position a fourth window as a subsubwindow (grandchild) of the second */
721 windows[3] = glutCreateSubWindow(windows[2],300,0,300,300);
722 printf ( "Creating window %d as subsubwindow to 'Second Window'\n", windows[3] ) ;
724 glClearColor(0.4f, 0.4f, 0.4f, 1.0);
726 /* callbacks and menus for this window */
727 SetWindowCallbacks( 0 );
728 glutSetCursor(GLUT_CURSOR_INHERIT); /* Inherit cursor look from parent (this is default on window creation) - comment the below to see in action */
729 glutSetCursor(GLUT_CURSOR_CYCLE);
732 printf ( "Please enter something to continue: " );
733 fgets ( dummy_string, STRING_LENGTH, stdin );
737 printf ( "Back from the 'freeglut' main loop\n" ) ;