e25404f6596c6919e5276ea1ac3ec0cc77aa1e83
[freeglut] / src / freeglut_init.c
1 /*
2  * freeglut_init.c
3  *
4  * Various freeglut initialization functions.
5  *
6  * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7  * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8  * Creation date: Thu Dec 2 1999
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a
11  * copy of this software and associated documentation files (the "Software"),
12  * to deal in the Software without restriction, including without limitation
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  * and/or sell copies of the Software, and to permit persons to whom the
15  * Software is furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included
18  * in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
23  * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include <GL/freeglut.h>
33 #include "freeglut_internal.h"
34
35 /*
36  * TODO BEFORE THE STABLE RELEASE:
37  *
38  *  fgDeinitialize()        -- Win32's OK, X11 needs the OS-specific
39  *                             deinitialization done
40  *  glutInitDisplayString() -- display mode string parsing
41  *
42  * Wouldn't it be cool to use gettext() for error messages? I just love
43  * bash saying  "nie znaleziono pliku" instead of "file not found" :)
44  * Is gettext easily portable?
45  */
46
47 /* -- GLOBAL VARIABLES ----------------------------------------------------- */
48
49 /*
50  * A structure pointed by g_pDisplay holds all information
51  * regarding the display, screen, root window etc.
52  */
53 SFG_Display fgDisplay;
54
55 /*
56  * The settings for the current freeglut session
57  */
58 SFG_State fgState = { { -1, -1, GL_FALSE },  /* Position */
59                       { 300, 300, GL_TRUE }, /* Size */
60                       GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH,  /* DisplayMode */
61                       GL_FALSE,              /* Initialised */
62                       GL_FALSE,              /* ForceDirectContext */
63                       GL_TRUE,               /* TryDirectContext */
64                       GL_FALSE,              /* ForceIconic */
65                       GL_FALSE,              /* UseCurrentContext */
66                       GL_FALSE,              /* GLDebugSwitch */
67                       GL_FALSE,              /* XSyncSwitch */
68                       GL_FALSE,              /* IgnoreKeyRepeat */
69                       0xffffffff,            /* Modifiers */
70                       0,                     /* FPSInterval */
71                       0,                     /* SwapCount */
72                       0,                     /* SwapTime */
73 #if TARGET_HOST_WIN32
74                       { 0, GL_FALSE },       /* Time */
75 #else
76                       { { 0, 0 }, GL_FALSE },
77 #endif
78                       { NULL, NULL },         /* Timers */
79                       { NULL, NULL },         /* FreeTimers */
80                       NULL,                   /* IdleCallback */
81                       0,                      /* ActiveMenus */
82                       NULL,                   /* MenuStateCallback */
83                       NULL,                   /* MenuStatusCallback */
84                       { 640, 480, GL_TRUE },  /* GameModeSize */
85                       16,                     /* GameModeDepth */
86                       72,                     /* GameModeRefresh */
87                       GLUT_ACTION_EXIT,       /* ActionOnWindowClose */
88                       GLUT_EXEC_STATE_INIT,   /* ExecState */
89                       NULL                    /* ProgramName */
90 };
91
92
93 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
94
95 /*
96  * A call to this function should initialize all the display stuff...
97  */
98 void fgInitialize( const char* displayName )
99 {
100 #if TARGET_HOST_UNIX_X11
101     fgDisplay.Display = XOpenDisplay( displayName );
102
103     if( fgDisplay.Display == NULL )
104         fgError( "failed to open display '%s'", XDisplayName( displayName ) );
105
106     if( !glXQueryExtension( fgDisplay.Display, NULL, NULL ) )
107         fgError( "OpenGL GLX extension not supported by display '%s'",
108             XDisplayName( displayName ) );
109
110     fgDisplay.Screen = DefaultScreen( fgDisplay.Display );
111     fgDisplay.RootWindow = RootWindow(
112         fgDisplay.Display,
113         fgDisplay.Screen
114     );
115
116     fgDisplay.ScreenWidth  = DisplayWidth(
117         fgDisplay.Display,
118         fgDisplay.Screen
119     );
120     fgDisplay.ScreenHeight = DisplayHeight(
121         fgDisplay.Display,
122         fgDisplay.Screen
123     );
124
125     fgDisplay.ScreenWidthMM = DisplayWidthMM(
126         fgDisplay.Display,
127         fgDisplay.Screen
128     );
129     fgDisplay.ScreenHeightMM = DisplayHeightMM(
130         fgDisplay.Display,
131         fgDisplay.Screen
132     );
133
134     fgDisplay.Connection = ConnectionNumber( fgDisplay.Display );
135
136     /*
137      * Create the window deletion atom
138      */
139     fgDisplay.DeleteWindow = XInternAtom(
140         fgDisplay.Display,
141         "WM_DELETE_WINDOW",
142         FALSE
143     );
144
145 #elif TARGET_HOST_WIN32
146
147     WNDCLASS wc;
148     ATOM atom;
149
150     /*
151      * What we need to do is to initialize the fgDisplay global structure here.
152      */
153     fgDisplay.Instance = GetModuleHandle( NULL );
154
155     atom = GetClassInfo( fgDisplay.Instance, "FREEGLUT", &wc );
156     if( atom == 0 )
157     {
158         ZeroMemory( &wc, sizeof(WNDCLASS) );
159
160         /*
161          * Each of the windows should have its own device context, and we
162          * want redraw events during Vertical and Horizontal Resizes by
163          * the user.
164          *
165          * XXX Old code had "| CS_DBCLCKS" commented out.  Plans for the
166          * XXX future?  Dead-end idea?
167          */
168         wc.style          = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
169         wc.lpfnWndProc    = fgWindowProc;
170         wc.cbClsExtra     = 0;
171         wc.cbWndExtra     = 0;
172         wc.hInstance      = fgDisplay.Instance;
173         wc.hIcon          = LoadIcon( fgDisplay.Instance, "GLUT_ICON" );
174         if (!wc.hIcon)
175           wc.hIcon        = LoadIcon( NULL, IDI_WINLOGO );
176
177         wc.hCursor        = LoadCursor( NULL, IDC_ARROW );
178         wc.hbrBackground  = NULL;
179         wc.lpszMenuName   = NULL;
180         wc.lpszClassName  = "FREEGLUT";
181
182         /*
183          * Register the window class
184          */
185         atom = RegisterClass( &wc );
186         assert( atom );
187     }
188
189     /*
190      * The screen dimensions can be obtained via GetSystemMetrics() calls
191      */
192     fgDisplay.ScreenWidth  = GetSystemMetrics( SM_CXSCREEN );
193     fgDisplay.ScreenHeight = GetSystemMetrics( SM_CYSCREEN );
194
195     {
196         HWND desktop = GetDesktopWindow( );
197         HDC  context = GetDC( desktop );
198
199         fgDisplay.ScreenWidthMM  = GetDeviceCaps( context, HORZSIZE );
200         fgDisplay.ScreenHeightMM = GetDeviceCaps( context, VERTSIZE );
201
202         ReleaseDC( desktop, context );
203     }
204
205 #endif
206
207     fgJoystickInit( 0 );
208     fgJoystickInit( 1 );
209
210     fgState.Initialised = GL_TRUE;
211 }
212
213 /*
214  * Perform the freeglut deinitialization...
215  */
216 void fgDeinitialize( void )
217 {
218     SFG_Timer *timer;
219
220     if( !fgState.Initialised )
221     {
222         fgWarning( "fgDeinitialize(): "
223                    "no valid initialization has been performed" );
224         return;
225     }
226
227     /* fgState.Initialised = GL_FALSE; */
228
229     /*
230      * If there was a menu created, destroy the rendering context
231      */
232     if( fgStructure.MenuContext )
233     {
234         free( fgStructure.MenuContext );
235         fgStructure.MenuContext = NULL;
236     }
237
238     fgDestroyStructure( );
239
240     while( (timer = fgState.Timers.First) )
241     {
242         fgListRemove( &fgState.Timers, &timer->Node );
243         free( timer );
244     }
245
246     while( (timer = fgState.FreeTimers.First) )
247     {
248         fgListRemove( &fgState.FreeTimers, &timer->Node );
249         free( timer );
250     }
251
252     fgJoystickClose( );
253
254     fgState.Initialised = GL_FALSE;
255
256     fgState.Position.X = -1;
257     fgState.Position.Y = -1;
258     fgState.Position.Use = GL_FALSE;
259
260     fgState.Size.X = 300;
261     fgState.Size.Y = 300;
262     fgState.Size.Use = GL_TRUE;
263
264     fgState.DisplayMode = GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH;
265
266     fgState.ForceDirectContext  = GL_FALSE;
267     fgState.TryDirectContext    = GL_TRUE;
268     fgState.ForceIconic         = GL_FALSE;
269     fgState.UseCurrentContext   = GL_FALSE;
270     fgState.GLDebugSwitch       = GL_FALSE;
271     fgState.XSyncSwitch         = GL_FALSE;
272     fgState.ActionOnWindowClose = GLUT_ACTION_EXIT;
273     fgState.ExecState           = GLUT_EXEC_STATE_INIT;
274
275     fgState.IgnoreKeyRepeat = GL_TRUE;
276     fgState.Modifiers       = 0xffffffff;
277
278     fgState.GameModeSize.X  = 640;
279     fgState.GameModeSize.Y  = 480;
280     fgState.GameModeDepth   =  16;
281     fgState.GameModeRefresh =  72;
282
283     fgState.Time.Set = GL_FALSE;
284
285     fgListInit( &fgState.Timers );
286     fgListInit( &fgState.FreeTimers );
287
288     fgState.IdleCallback = NULL;
289     fgState.MenuStateCallback = ( FGCBMenuState )NULL;
290     fgState.MenuStatusCallback = ( FGCBMenuStatus )NULL;
291
292     fgState.SwapCount   = 0;
293     fgState.SwapTime    = 0;
294     fgState.FPSInterval = 0;
295
296     if( fgState.ProgramName )
297     {
298         free( fgState.ProgramName );
299         fgState.ProgramName = NULL;
300     }
301
302
303 #if TARGET_HOST_UNIX_X11
304
305     /*
306      * Make sure all X-client data we have created will be destroyed on
307      * display closing
308      */
309     XSetCloseDownMode( fgDisplay.Display, DestroyAll );
310
311     /*
312      * Close the display connection, destroying all windows we have
313      * created so far
314      */
315     XCloseDisplay( fgDisplay.Display );
316
317 #endif
318 }
319
320 /*
321  * Everything inside the following #ifndef is copied from the X sources.
322  */
323
324 #if TARGET_HOST_WIN32
325
326 /*
327
328 Copyright 1985, 1986, 1987,1998  The Open Group
329
330 Permission to use, copy, modify, distribute, and sell this software and its
331 documentation for any purpose is hereby granted without fee, provided that
332 the above copyright notice appear in all copies and that both that
333 copyright notice and this permission notice appear in supporting
334 documentation.
335
336 The above copyright notice and this permission notice shall be included
337 in all copies or substantial portions of the Software.
338
339 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
340 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
341 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
342 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
343 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
344 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
345 OTHER DEALINGS IN THE SOFTWARE.
346
347 Except as contained in this notice, the name of The Open Group shall
348 not be used in advertising or otherwise to promote the sale, use or
349 other dealings in this Software without prior written authorization
350 from The Open Group.
351
352 */
353
354 #define NoValue         0x0000
355 #define XValue          0x0001
356 #define YValue          0x0002
357 #define WidthValue      0x0004
358 #define HeightValue     0x0008
359 #define AllValues       0x000F
360 #define XNegative       0x0010
361 #define YNegative       0x0020
362
363 /*
364  *    XParseGeometry parses strings of the form
365  *   "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
366  *   width, height, xoffset, and yoffset are unsigned integers.
367  *   Example:  "=80x24+300-49"
368  *   The equal sign is optional.
369  *   It returns a bitmask that indicates which of the four values
370  *   were actually found in the string.  For each value found,
371  *   the corresponding argument is updated;  for each value
372  *   not found, the corresponding argument is left unchanged.
373  */
374
375 static int
376 ReadInteger(char *string, char **NextString)
377 {
378     register int Result = 0;
379     int Sign = 1;
380
381     if (*string == '+')
382         string++;
383     else if (*string == '-')
384     {
385         string++;
386         Sign = -1;
387     }
388     for (; (*string >= '0') && (*string <= '9'); string++)
389     {
390         Result = (Result * 10) + (*string - '0');
391     }
392     *NextString = string;
393     if (Sign >= 0)
394         return Result;
395     else
396         return -Result;
397 }
398
399 static int XParseGeometry (
400     const char *string,
401     int *x,
402     int *y,
403     unsigned int *width,    /* RETURN */
404     unsigned int *height)    /* RETURN */
405 {
406     int mask = NoValue;
407     register char *strind;
408     unsigned int tempWidth = 0, tempHeight = 0;
409     int tempX = 0, tempY = 0;
410     char *nextCharacter;
411
412     if ( (string == NULL) || (*string == '\0'))
413       return mask;
414     if (*string == '=')
415         string++;  /* ignore possible '=' at beg of geometry spec */
416
417     strind = (char *)string;
418     if (*strind != '+' && *strind != '-' && *strind != 'x') {
419         tempWidth = ReadInteger(strind, &nextCharacter);
420         if (strind == nextCharacter)
421             return 0;
422         strind = nextCharacter;
423         mask |= WidthValue;
424     }
425
426     if (*strind == 'x' || *strind == 'X') {
427         strind++;
428         tempHeight = ReadInteger(strind, &nextCharacter);
429         if (strind == nextCharacter)
430             return 0;
431         strind = nextCharacter;
432         mask |= HeightValue;
433     }
434
435     if ((*strind == '+') || (*strind == '-')) {
436         if (*strind == '-') {
437             strind++;
438             tempX = -ReadInteger(strind, &nextCharacter);
439             if (strind == nextCharacter)
440                 return 0;
441             strind = nextCharacter;
442             mask |= XNegative;
443         }
444         else
445         {
446             strind++;
447             tempX = ReadInteger(strind, &nextCharacter);
448             if (strind == nextCharacter)
449                 return 0;
450             strind = nextCharacter;
451         }
452         mask |= XValue;
453         if ((*strind == '+') || (*strind == '-')) {
454             if (*strind == '-') {
455                 strind++;
456                 tempY = -ReadInteger(strind, &nextCharacter);
457                 if (strind == nextCharacter)
458                     return 0;
459                 strind = nextCharacter;
460                 mask |= YNegative;
461             }
462             else
463             {
464                 strind++;
465                 tempY = ReadInteger(strind, &nextCharacter);
466                 if (strind == nextCharacter)
467                     return 0;
468                 strind = nextCharacter;
469             }
470             mask |= YValue;
471         }
472     }
473
474     /* If strind isn't at the end of the string the it's an invalid
475        geometry specification. */
476
477     if (*strind != '\0') return 0;
478
479     if (mask & XValue)
480         *x = tempX;
481     if (mask & YValue)
482         *y = tempY;
483     if (mask & WidthValue)
484         *width = tempWidth;
485     if (mask & HeightValue)
486         *height = tempHeight;
487     return mask;
488 }
489 #endif
490
491 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
492
493 /*
494  * Perform initialization. This usually happens on the program startup
495  * and restarting after glutMainLoop termination...
496  */
497 void FGAPIENTRY glutInit( int* pargc, char** argv )
498 {
499     char* displayName = NULL;
500     char* geometry = NULL;
501     int i, j, argc = *pargc;
502
503     if( fgState.Initialised )
504         fgError( "illegal glutInit() reinitialization attempt" );
505
506     if (pargc && *pargc && argv && *argv && **argv)
507     {
508         fgState.ProgramName = strdup (*argv);
509
510         if( !fgState.ProgramName )
511             fgError ("Could not allocate space for the program's name.");
512     }
513
514     fgCreateStructure( );
515
516     fgElapsedTime( );
517
518     /* check if GLUT_FPS env var is set */
519     {
520         const char *fps = getenv( "GLUT_FPS" );
521         if( fps )
522         {
523             int interval;
524             sscanf( fps, "%d", &interval );
525
526             if( interval <= 0 )
527                 fgState.FPSInterval = 5000;  /* 5000 millisecond default */
528             else
529                 fgState.FPSInterval = interval;
530         }
531     }
532
533     displayName = getenv( "DISPLAY");
534
535     for( i = 1; i < argc; i++ )
536     {
537         if( strcmp( argv[ i ], "-display" ) == 0 )
538         {
539             if( ++i >= argc )
540                 fgError( "-display parameter must be followed by display name" );
541
542             displayName = argv[ i ];
543
544             argv[ i - 1 ] = NULL;
545             argv[ i     ] = NULL;
546             ( *pargc ) -= 2;
547         }
548         else if( strcmp( argv[ i ], "-geometry" ) == 0 )
549         {
550             if( ++i >= argc )
551                 fgError( "-geometry parameter must be followed by window "
552                          "geometry settings" );
553
554             geometry = argv[ i ];
555
556             argv[ i - 1 ] = NULL;
557             argv[ i     ] = NULL;
558             ( *pargc ) -= 2;
559         }
560         else if( strcmp( argv[ i ], "-direct" ) == 0)
561         {
562             if( ! fgState.TryDirectContext )
563                 fgError( "parameters ambiguity, -direct and -indirect "
564                     "cannot be both specified" );
565
566             fgState.ForceDirectContext = GL_TRUE;
567             argv[ i ] = NULL;
568             ( *pargc )--;
569         }
570         else if( strcmp( argv[ i ], "-indirect" ) == 0 )
571         {
572             if( fgState.ForceDirectContext )
573                 fgError( "parameters ambiguity, -direct and -indirect "
574                     "cannot be both specified" );
575
576             fgState.TryDirectContext = GL_FALSE;
577             argv[ i ] = NULL;
578             (*pargc)--;
579         }
580         else if( strcmp( argv[ i ], "-iconic" ) == 0 )
581         {
582             fgState.ForceIconic = GL_TRUE;
583             argv[ i ] = NULL;
584             ( *pargc )--;
585         }
586         else if( strcmp( argv[ i ], "-gldebug" ) == 0 )
587         {
588             fgState.GLDebugSwitch = GL_TRUE;
589             argv[ i ] = NULL;
590             ( *pargc )--;
591         }
592         else if( strcmp( argv[ i ], "-sync" ) == 0 )
593         {
594             fgState.XSyncSwitch = GL_TRUE;
595             argv[ i ] = NULL;
596             ( *pargc )--;
597         }
598     }
599
600     /*
601      * Compact {argv}.
602      */
603     j = 2;
604     for( i = 1; i < *pargc; i++, j++ )
605     {
606         if( argv[ i ] == NULL )
607         {
608             /* Guaranteed to end because there are "*pargc" arguments left */
609             while ( argv[ j ] == NULL )
610                 j++;
611             argv[ i ] = argv[ j ];
612         }
613     }
614
615     /*
616      * Have the display created now. If there wasn't a "-display"
617      * in the program arguments, we will use the DISPLAY environment
618      * variable for opening the X display (see code above):
619      */
620     fgInitialize( displayName );
621
622     /*
623      * Geometry parsing deffered until here because we may need the screen
624      * size.
625      */
626
627     if (geometry )
628     {
629         int mask = XParseGeometry( geometry,
630                                    &fgState.Position.X, &fgState.Position.Y,
631                                    &fgState.Size.X, &fgState.Size.Y );
632
633         if( (mask & (WidthValue|HeightValue)) == (WidthValue|HeightValue) )
634             fgState.Size.Use = GL_TRUE;
635
636         if( mask & XNegative )
637             fgState.Position.X += fgDisplay.ScreenWidth - fgState.Size.X;
638
639         if( mask & YNegative )
640             fgState.Position.Y += fgDisplay.ScreenHeight - fgState.Size.Y;
641
642         if( (mask & (XValue|YValue)) == (XValue|YValue) )
643             fgState.Position.Use = GL_TRUE;
644     }
645 }
646
647 /*
648  * Sets the default initial window position for new windows
649  */
650 void FGAPIENTRY glutInitWindowPosition( int x, int y )
651 {
652     fgState.Position.X = x;
653     fgState.Position.Y = y;
654
655     if( ( x >= 0 ) && ( y >= 0 ) )
656         fgState.Position.Use = GL_TRUE;
657     else
658         fgState.Position.Use = GL_FALSE;
659 }
660
661 /*
662  * Sets the default initial window size for new windows
663  */
664 void FGAPIENTRY glutInitWindowSize( int width, int height )
665 {
666     fgState.Size.X = width;
667     fgState.Size.Y = height;
668
669     if( ( width > 0 ) && ( height > 0 ) )
670         fgState.Size.Use = GL_TRUE;
671     else
672         fgState.Size.Use = GL_FALSE;
673 }
674
675 /*
676  * Sets the default display mode for all new windows
677  */
678 void FGAPIENTRY glutInitDisplayMode( unsigned int displayMode )
679 {
680     /*
681      * We will make use of this value when creating a new OpenGL context...
682      */
683     fgState.DisplayMode = displayMode;
684 }
685
686
687 /* -- INIT DISPLAY STRING PARSING ------------------------------------------ */
688
689 #define NUM_TOKENS             28
690 static char* Tokens[] =
691 {
692     "alpha", "acca", "acc", "blue", "buffer", "conformant", "depth", "double",
693     "green", "index", "num", "red", "rgba", "rgb", "luminance", "stencil",
694     "single", "stereo", "samples", "slow", "win32pdf", "xvisual",
695     "xstaticgray", "xgrayscale", "xstaticcolor", "xpseudocolor",
696     "xtruecolor", "xdirectcolor"
697 };
698
699 static int TokenLengths[] =
700 {
701     5,       4,      3,     4,      6,        10,           5,       6,
702     5,       5,       3,     3,     4,      3,     9,           7,
703     6,        6,        7,         4,      8,          7,
704     11,            10,           12,             12,
705     10,           12
706 };
707
708 void FGAPIENTRY glutInitDisplayString( const char* displayMode )
709 {
710     int glut_state_flag = 0 ;
711     /*
712      * Unpack a lot of options from a character string.  The options are
713      * delimited by blanks or tabs.
714      */
715     char *token ;
716     int len = strlen ( displayMode );
717     char *buffer = (char *)malloc ( (len+1) * sizeof(char) );
718     memcpy ( buffer, displayMode, len );
719     buffer[len] = '\0';
720
721     token = strtok ( buffer, " \t" );
722     while ( token )
723     {
724         /*
725          * Process this token
726          */
727         int i ;
728         for ( i = 0; i < NUM_TOKENS; i++ )
729         {
730             if ( strncmp ( token, Tokens[i], TokenLengths[i] ) == 0 ) break ;
731         }
732
733         switch ( i )
734         {
735         case 0 :  /* "alpha":  Alpha color buffer precision in bits */
736             glut_state_flag |= GLUT_ALPHA ;  /* Somebody fix this for me! */
737             break ;
738
739         case 1 :  /* "acca":  Red, green, blue, and alpha accumulation buffer
740                      precision in bits */
741             break ;
742
743         case 2 :  /* "acc":  Red, green, and blue accumulation buffer precision
744                      in bits with zero bits alpha */
745             glut_state_flag |= GLUT_ACCUM ;  /* Somebody fix this for me! */
746             break ;
747
748         case 3 :  /* "blue":  Blue color buffer precision in bits */
749             break ;
750
751         case 4 :  /* "buffer":  Number of bits in the color index color buffer
752                    */
753             break ;
754
755         case 5 :  /* "conformant":  Boolean indicating if the frame buffer
756                      configuration is conformant or not */
757             break ;
758
759         case 6 : /* "depth":  Number of bits of precsion in the depth buffer */
760             glut_state_flag |= GLUT_DEPTH ;  /* Somebody fix this for me! */
761             break ;
762
763         case 7 :  /* "double":  Boolean indicating if the color buffer is
764                      double buffered */
765             glut_state_flag |= GLUT_DOUBLE ;
766             break ;
767
768         case 8 :  /* "green":  Green color buffer precision in bits */
769             break ;
770
771         case 9 :  /* "index":  Boolean if the color model is color index or not
772                    */
773             glut_state_flag |= GLUT_INDEX ;
774             break ;
775
776         case 10 :  /* "num":  A special capability  name indicating where the
777                       value represents the Nth frame buffer configuration
778                       matching the description string */
779             break ;
780
781         case 11 :  /* "red":  Red color buffer precision in bits */
782             break ;
783
784         case 12 :  /* "rgba":  Number of bits of red, green, blue, and alpha in
785                       the RGBA color buffer */
786             glut_state_flag |= GLUT_RGBA ;  /* Somebody fix this for me! */
787             break ;
788
789         case 13 :  /* "rgb":  Number of bits of red, green, and blue in the
790                       RGBA color buffer with zero bits alpha */
791             glut_state_flag |= GLUT_RGB ;  /* Somebody fix this for me! */
792             break ;
793
794         case 14 :  /* "luminance":  Number of bits of red in the RGBA and zero
795                       bits of green, blue (alpha not specified) of color buffer
796                       precision */
797             glut_state_flag |= GLUT_LUMINANCE ; /* Somebody fix this for me! */
798             break ;
799
800         case 15 :  /* "stencil":  Number of bits in the stencil buffer */
801             glut_state_flag |= GLUT_STENCIL;  /* Somebody fix this for me! */
802             break ;
803
804         case 16 :  /* "single":  Boolean indicate the color buffer is single
805                       buffered */
806             glut_state_flag |= GLUT_SINGLE ;
807             break ;
808
809         case 17 :  /* "stereo":  Boolean indicating the color buffer supports
810                       OpenGL-style stereo */
811             glut_state_flag |= GLUT_STEREO ;
812             break ;
813
814         case 18 :  /* "samples":  Indicates the number of multisamples to use
815                       based on GLX's SGIS_multisample extension (for
816                       antialiasing) */
817             glut_state_flag |= GLUT_MULTISAMPLE ; /*Somebody fix this for me!*/
818             break ;
819
820         case 19 :  /* "slow":  Boolean indicating if the frame buffer
821                       configuration is slow or not */
822             break ;
823
824         case 20 :  /* "win32pdf":  matches the Win32 Pixel Format Descriptor by
825                       number */
826 #if TARGET_HOST_WIN32
827 #endif
828             break ;
829
830         case 21 :  /* "xvisual":  matches the X visual ID by number */
831 #if TARGET_HOST_UNIX_X11
832 #endif
833             break ;
834
835         case 22 :  /* "xstaticgray":  boolean indicating if the frame buffer
836                       configuration's X visual is of type StaticGray */
837 #if TARGET_HOST_UNIX_X11
838 #endif
839             break ;
840
841         case 23 :  /* "xgrayscale":  boolean indicating if the frame buffer
842                       configuration's X visual is of type GrayScale */
843 #if TARGET_HOST_UNIX_X11
844 #endif
845             break ;
846
847         case 24 :  /* "xstaticcolor":  boolean indicating if the frame buffer
848                       configuration's X visual is of type StaticColor */
849 #if TARGET_HOST_UNIX_X11
850 #endif
851             break ;
852
853         case 25 :  /* "xpseudocolor":  boolean indicating if the frame buffer
854                       configuration's X visual is of type PseudoColor */
855 #if TARGET_HOST_UNIX_X11
856 #endif
857             break ;
858
859         case 26 :  /* "xtruecolor":  boolean indicating if the frame buffer
860                       configuration's X visual is of type TrueColor */
861 #if TARGET_HOST_UNIX_X11
862 #endif
863             break ;
864
865         case 27 :  /* "xdirectcolor":  boolean indicating if the frame buffer
866                       configuration's X visual is of type DirectColor */
867 #if TARGET_HOST_UNIX_X11
868 #endif
869             break ;
870
871         case 28 :  /* Unrecognized */
872             printf ( "WARNING - Display string token not recognized:  %s\n",
873                      token );
874             break ;
875         }
876
877         token = strtok ( NULL, " \t" );
878     }
879
880     free ( buffer );
881
882     /*
883      * We will make use of this value when creating a new OpenGL context...
884      */
885     fgState.DisplayMode = glut_state_flag;
886 }
887
888 /*** END OF FILE ***/