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