4 * Various freeglut initialization functions.
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
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:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
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.
32 #define G_LOG_DOMAIN "freeglut-init"
34 #include "../include/GL/freeglut.h"
35 #include "freeglut_internal.h"
38 * TODO BEFORE THE STABLE RELEASE:
40 * fgDeinitialize() -- Win32's OK, X11 needs the OS-specific deinitialization done
41 * glutInitDisplayString() -- display mode string parsing
43 * Wouldn't it be cool to use gettext() for error messages? I just love bash saying
44 * "nie znaleziono pliku" instead of "file not found" :) Is gettext easily portable?
47 /* -- GLOBAL VARIABLES ----------------------------------------------------- */
50 * A structure pointed by g_pDisplay holds all information
51 * regarding the display, screen, root window etc.
53 SFG_Display fgDisplay;
56 * The settings for the current freeglut session
58 SFG_State fgState = { { -1, -1, FALSE }, /* Position */
59 { 300, 300, TRUE }, /* Size */
60 GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH, /* DisplayMode */
61 FALSE, /* ForceDirectContext */
62 TRUE, /* TryDirectContext */
63 FALSE, /* ForceIconic */
64 FALSE, /* GLDebugSwitch */
65 FALSE, /* XSyncSwitch */
66 TRUE, /* IgnoreKeyRepeat */
70 #ifdef TARGET_HOST_WIN32
71 { 0, FALSE }, /* Time */
75 { NULL, NULL }, /* Timers */
76 NULL, /* IdleCallback */
77 NULL, /* MenuStateCallback */
78 NULL, /* MenuStatusCallback */
79 { 640, 480, TRUE }, /* GameModeSize */
80 16, /* GameModeDepth */
81 72, /* GameModeRefresh */
82 GLUT_ACTION_EXIT, /* ActionOnWindowClose */
83 GLUT_EXEC_STATE_INIT /* ExecState */
87 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
90 * A call to this function should initialize all the display stuff...
92 void fgInitialize( const char* displayName )
94 #if TARGET_HOST_UNIX_X11
96 * Have the display created
98 fgDisplay.Display = XOpenDisplay( displayName );
100 if( fgDisplay.Display == NULL )
103 * Failed to open a display. That's no good.
105 fgError( "failed to open display '%s'", XDisplayName( displayName ) );
109 * Check for the OpenGL GLX extension availability:
111 if( !glXQueryExtension( fgDisplay.Display, NULL, NULL ) )
114 * GLX extensions have not been found...
116 fgError( "OpenGL GLX extension not supported by display '%s'", XDisplayName( displayName ) );
120 * Grab the default screen for the display we have just opened
122 fgDisplay.Screen = DefaultScreen( fgDisplay.Display );
125 * The same applying to the root window
127 fgDisplay.RootWindow = RootWindow(
133 * Grab the logical screen's geometry
135 fgDisplay.ScreenWidth = DisplayWidth(
140 fgDisplay.ScreenHeight = DisplayHeight(
146 * Grab the physical screen's geometry
148 fgDisplay.ScreenWidthMM = DisplayWidthMM(
153 fgDisplay.ScreenHeightMM = DisplayHeightMM(
159 * The display's connection number
161 fgDisplay.Connection = ConnectionNumber( fgDisplay.Display );
164 * Create the window deletion atom
166 fgDisplay.DeleteWindow = XInternAtom(
172 #elif TARGET_HOST_WIN32
178 * What we need to do is to initialize the fgDisplay global structure here...
180 fgDisplay.Instance = GetModuleHandle( NULL );
183 * Check if the freeglut window class has been registered before...
185 atom = GetClassInfo( fgDisplay.Instance, "FREEGLUT", &wc );
188 * ...nope, it has not, and we have to do it right now:
193 * Make sure the unitialized fields are reset to zero
195 ZeroMemory( &wc, sizeof(WNDCLASS) );
198 * Each of the windows should have its own device context...
201 wc.lpfnWndProc = fgWindowProc;
204 wc.hInstance = fgDisplay.Instance;
205 wc.hIcon = LoadIcon( fgDisplay.Instance, "GLUT_ICON" );
207 wc.hIcon = LoadIcon( NULL, IDI_WINLOGO );
209 wc.hCursor = LoadCursor( NULL, IDC_ARROW );
210 wc.hbrBackground = NULL;
211 wc.lpszMenuName = NULL;
212 wc.lpszClassName = "FREEGLUT";
215 * Register the window class
217 atom = RegisterClass( &wc );
222 * The screen dimensions can be obtained via GetSystemMetrics() calls
224 fgDisplay.ScreenWidth = GetSystemMetrics( SM_CXSCREEN );
225 fgDisplay.ScreenHeight = GetSystemMetrics( SM_CYSCREEN );
229 * Checking the display's size in millimeters isn't too hard, too:
231 HWND desktop = GetDesktopWindow();
232 HDC context = GetDC( desktop );
235 * Grab the appropriate values now (HORZSIZE and VERTSIZE respectably):
237 fgDisplay.ScreenWidthMM = GetDeviceCaps( context, HORZSIZE );
238 fgDisplay.ScreenHeightMM = GetDeviceCaps( context, VERTSIZE );
241 * Whoops, forgot to release the device context :)
243 ReleaseDC( desktop, context );
249 * Have the joystick device initialized now
255 * Perform the freeglut deinitialization...
257 void fgDeinitialize( void )
262 * Check if initialization has been performed before
264 if( !fgState.Time.Set )
266 fgWarning( "fgDeinitialize(): fgState.Timer is null => no valid initialization has been performed" );
271 * Perform the freeglut structure deinitialization
273 fgDestroyStructure();
276 * Delete all the timers and their storage list
278 while ( (timer = fgState.Timers.First) != NULL )
280 fgListRemove ( &fgState.Timers, &timer->Node ) ;
285 * Deinitialize the joystick device
290 * Reset the state structure
293 fgState.Position.X = -1 ;
294 fgState.Position.Y = -1 ;
295 fgState.Position.Use = FALSE ;
297 fgState.Size.X = 300 ;
298 fgState.Size.Y = 300 ;
299 fgState.Size.Use = TRUE ;
302 * The default display mode to be used
304 fgState.DisplayMode = GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH;
306 fgState.ForceDirectContext = FALSE;
307 fgState.TryDirectContext = TRUE;
308 fgState.ForceIconic = FALSE;
309 fgState.GLDebugSwitch = FALSE;
310 fgState.XSyncSwitch = FALSE;
311 fgState.ActionOnWindowClose = GLUT_ACTION_EXIT ;
312 fgState.ExecState = GLUT_EXEC_STATE_INIT ;
315 * Assume we want to ignore the automatic key repeat
317 fgState.IgnoreKeyRepeat = TRUE;
320 * Set the default game mode settings
322 fgState.GameModeSize.X = 640;
323 fgState.GameModeSize.Y = 480;
324 fgState.GameModeDepth = 16;
325 fgState.GameModeRefresh = 72;
327 fgState.Time.Set = FALSE ;
329 fgState.Timers.First = fgState.Timers.Last = NULL ;
330 fgState.IdleCallback = NULL ;
331 fgState.MenuStateCallback = (FGCBmenuState)NULL ;
332 fgState.MenuStatusCallback = (FGCBmenuStatus)NULL ;
337 fgState.SwapCount = 0;
338 fgState.SwapTime = 0;
339 fgState.FPSInterval = 0;
342 #if TARGET_HOST_UNIX_X11
345 * Make sure all X-client data we have created will be destroyed on display closing
347 XSetCloseDownMode( fgDisplay.Display, DestroyAll );
350 * Close the display connection, destroying all windows we have created so far
352 XCloseDisplay( fgDisplay.Display );
358 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
361 * Perform initialization. This usually happens on the program startup
362 * and restarting after glutMainLoop termination...
364 void FGAPIENTRY glutInit( int* pargc, char** argv )
366 char* displayName = NULL;
367 int i, j, argc = *pargc;
370 * Do not allow multiple initialization of the library
372 if( fgState.Time.Set )
375 * We can't have multiple initialization performed
377 fgError( "illegal glutInit() reinitialization attemp" );
381 * Have the internal freeglut structure initialized now
386 * Remember the function's call time
388 #if TARGET_HOST_UNIX_X11
389 gettimeofday(&fgState.Time.Value, NULL);
390 #elif TARGET_HOST_WIN32
391 fgState.Time.Value = timeGetTime();
393 fgState.Time.Set = TRUE;
396 /* check if GLUT_FPS env var is set */
398 const char *fps = getenv("GLUT_FPS");
400 sscanf(fps, "%d", &fgState.FPSInterval);
401 if (fgState.FPSInterval <= 0)
402 fgState.FPSInterval = 5000; /* 5000 milliseconds */
407 * Grab the environment variable indicating the X display to use.
408 * This is harmless under Win32, so let's let it stay here...
410 #if TARGET_HOST_WIN32
411 if ( !getenv ( "DISPLAY" ) )
412 displayName = strdup ( "" ) ;
415 displayName = strdup( getenv( "DISPLAY" ) );
418 * Have the program arguments parsed.
420 for( i=1; i<argc; i++ )
423 * The X display name settings
425 if( strcmp( argv[ i ], "-display" ) == 0 )
428 * Check for possible lack of the next argument
431 fgError( "-display parameter must be followed by display name" );
434 * Release the previous display name (the one from app's environment)
439 * Make a working copy of the name for us to use
441 displayName = strdup( argv[ i ] );
444 * Have both arguments removed
446 argv[ i - 1 ] = NULL;
452 * The geometry settings
454 else if( strcmp( argv[ i ], "-geometry" ) == 0 )
460 * Again, check if there is at least one more argument
463 fgError( "-geometry parameter must be followed by window geometry settings" );
466 * Otherwise scan the geometry settings...
468 result = sscanf ( argv[i], "%dx%d+%d+%d", &x, &y, &w, &h );
471 * Check what we have been supplied with...
482 fgState.Position.Y = fgDisplay.ScreenHeight + y - fgState.Size.Y;
484 fgState.Position.Y = y;
490 fgState.Position.X = fgDisplay.ScreenWidth + x - fgState.Size.X;
492 fgState.Position.X = x;
496 * Have both arguments removed
498 argv[ i - 1 ] = NULL;
504 * The direct/indirect OpenGL contexts settings
506 else if( strcmp( argv[ i ], "-direct" ) == 0)
509 * We try to force direct rendering...
511 if( fgState.TryDirectContext == FALSE )
512 fgError( "parameters ambiguity, -direct and -indirect cannot be both specified" );
514 fgState.ForceDirectContext = TRUE;
518 else if( strcmp( argv[ i ], "-indirect" ) == 0 )
521 * We try to force indirect rendering...
523 if( fgState.ForceDirectContext == TRUE )
524 fgError( "parameters ambiguity, -direct and -indirect cannot be both specified" );
526 fgState.TryDirectContext = FALSE;
532 * The '-iconic' parameter makes all new top-level
533 * windows created in iconified state...
535 else if( strcmp( argv[ i ], "-iconic" ) == 0 )
537 fgState.ForceIconic = TRUE;
543 * The '-gldebug' option activates some OpenGL state debugging features
545 else if( strcmp( argv[ i ], "-gldebug" ) == 0 )
547 fgState.GLDebugSwitch = TRUE;
553 * The '-sync' option activates X protocol synchronization (for debugging purposes)
555 else if( strcmp( argv[ i ], "-sync" ) == 0 )
557 fgState.XSyncSwitch = TRUE;
564 * Have the arguments list compacted now
567 for( i = 1; i < *pargc; i++, j++ )
569 if( argv[ i ] == NULL )
571 while ( argv[j] == NULL ) j++ ; /* Guaranteed to end because there are "*pargc" arguments left */
577 * Have the display created now. As I am too lazy to implement
578 * the program arguments parsing, we will have the DISPLAY
579 * environment variable used for opening the X display:
581 fgInitialize( displayName );
584 * Check for the minus one settings for both position and size...
586 if( fgState.Position.X < 0 || fgState.Position.Y < 0 )
587 fgState.Position.Use = FALSE;
589 if( fgState.Size.X < 0 || fgState.Size.Y < 0 )
590 fgState.Size.Use = FALSE;
593 * Do not forget about releasing the display name string
599 * Sets the default initial window position for new windows
601 void FGAPIENTRY glutInitWindowPosition( int x, int y )
604 * The settings can be disables when both coordinates are negative
606 if( (x >= 0) && (y >= 0) )
609 * We want to specify the initial position of each of the windows
611 fgState.Position.X = x;
612 fgState.Position.Y = y;
613 fgState.Position.Use = TRUE;
618 * The initial position of each of the windows is specified by the wm
620 fgState.Position.X = -1;
621 fgState.Position.Y = -1;
622 fgState.Position.Use = FALSE;
627 * Sets the default initial window size for new windows
629 void FGAPIENTRY glutInitWindowSize( int width, int height )
632 * The settings can be disables when both values are negative
634 if( (width > 0) && (height > 0) )
637 * We want to specify the initial size of each of the windows
639 fgState.Size.X = width;
640 fgState.Size.Y = height;
641 fgState.Size.Use = TRUE;
646 * The initial size of each of the windows is specified by the wm (officially this is an error condition)
650 fgState.Size.Use = FALSE;
655 * Sets the default display mode for all new windows
657 void FGAPIENTRY glutInitDisplayMode( unsigned int displayMode )
660 * We will make use of this value when creating a new OpenGL context...
662 fgState.DisplayMode = displayMode;
666 /* -- INIT DISPLAY STRING PARSING ------------------------------------------ */
668 #if 0 /* FIXME: CJP */
670 * There is a discrete number of comparison operators we can encounter:
672 * comparison ::= "=" | "!=" | "<" | ">" | "<=" | ">=" | "~"
674 #define FG_NONE 0x0000
675 #define FG_EQUAL 0x0001
676 #define FG_NOT_EQUAL 0x0002
677 #define FG_LESS 0x0003
678 #define FG_MORE 0x0004
679 #define FG_LESS_OR_EQUAL 0x0005
680 #define FG_MORE_OR_EQUAL 0x0006
681 #define FG_CLOSEST 0x0007
684 * The caller can feed us with a number of capability tokens:
686 * capability ::= "alpha" | "acca" | "acc" | "blue" | "buffer" | "conformant" | "depth" | "double" |
687 * "green" | "index" | "num" | "red" | "rgba" | "rgb" | "luminance" | "stencil" |
688 * "single" | "stereo" | "samples" | "slow" | "win32pdf" | "xvisual" | "xstaticgray" |
689 * "xgrayscale" | "xstaticcolor" | "xpseudocolor" | "xtruecolor" | "xdirectcolor"
691 static gchar* g_Tokens[] =
693 "none", "alpha", "acca", "acc", "blue", "buffer", "conformant", "depth", "double", "green",
694 "index", "num", "red", "rgba", "rgb", "luminance", "stencil", "single", "stereo", "samples",
695 "slow", "win32pdf", "xvisual", "xstaticgray", "xgrayscale", "xstaticcolor", "xpseudocolor",
696 "xtruecolor", "xdirectcolor", NULL
700 * The structure to hold the parsed display string tokens
702 typedef struct tagSFG_Capability SFG_Capability;
703 struct tagSFG_Capability
705 gint capability; /* the capability token enumerator */
706 gint comparison; /* the comparison operator used */
707 gint value; /* the value we're comparing to */
711 * The scanner configuration for the init display string
713 static GScannerConfig fgInitDisplayStringScannerConfig =
715 ( " \t\r\n" ) /* cset_skip_characters */,
720 ) /* cset_identifier_first */,
728 ) /* cset_identifier_nth */,
729 ( "#\n" ) /* cpair_comment_single */,
730 FALSE /* case_sensitive */,
731 TRUE /* skip_comment_multi */,
732 TRUE /* skip_comment_single */,
733 TRUE /* scan_comment_multi */,
734 TRUE /* scan_identifier */,
735 FALSE /* scan_identifier_1char */,
736 FALSE /* scan_identifier_NULL */,
737 TRUE /* scan_symbols */,
738 FALSE /* scan_binary */,
739 TRUE /* scan_octal */,
740 TRUE /* scan_float */,
742 FALSE /* scan_hex_dollar */,
743 TRUE /* scan_string_sq */,
744 TRUE /* scan_string_dq */,
745 TRUE /* numbers_2_int */,
746 FALSE /* int_2_float */,
747 FALSE /* identifier_2_string */,
748 TRUE /* char_2_token */,
749 FALSE /* symbol_2_token */,
750 FALSE /* scope_0_fallback */,
754 * Sets the default display mode for all new windows using a string
756 void FGAPIENTRY glutInitDisplayString( char* displayMode )
759 * display_string ::= (switch)
760 * switch ::= capability [comparison value]
761 * comparison ::= "=" | "!=" | "<" | ">" | "<=" | ">=" | "~"
762 * capability ::= "alpha" | "acca" | "acc" | "blue" | "buffer" | "conformant" |
763 * "depth" | "double" | "green" | "index" | "num" | "red" | "rgba" |
764 * "rgb" | "luminance" | "stencil" | "single" | "stereo" |
765 * "samples" | "slow" | "win32pdf" | "xvisual" | "xstaticgray" |
766 * "xgrayscale" | "xstaticcolor" | "xpseudocolor" |
767 * "xtruecolor" | "xdirectcolor"
768 * value ::= 0..9 [value]
770 * The display string grammar. This should be EBNF, but I couldn't find the definitions so, to
771 * clarify: (expr) means 0 or more times the expression, [expr] means 0 or 1 times expr.
773 * Create a new GLib lexical analyzer to process the display mode string
775 GScanner* scanner = g_scanner_new( &fgInitDisplayStringScannerConfig );
780 * Fail if the display mode string is empty or the scanner failed to initialize
782 freeglut_return_if_fail( (scanner != NULL) && (strlen( displayMode ) > 0) );
785 * Set the scanner's input name (for debugging)
787 scanner->input_name = "glutInitDisplayString";
790 * Start the lexical analysis of the extensions string
792 g_scanner_input_text( scanner, displayMode, strlen( displayMode ) );
795 * While there are any more tokens to be checked...
797 while( !g_scanner_eof( scanner ) )
800 * Actually we're expecting only string tokens
802 GTokenType tokenType = g_scanner_get_next_token( scanner );
805 * We are looking for identifiers
807 if( tokenType == G_TOKEN_IDENTIFIER )
809 gchar* capability = NULL; /* the capability identifier string (always present) */
810 gint capID = 0; /* the capability identifier value (from g_Tokens) */
811 gint comparison = 0; /* the comparison operator value, see definitions */
812 gchar* valueString = NULL; /* if the previous one is present, this is needed */
813 gint value = 0; /* the integer value converted using a strtol call */
814 SFG_Capability* capStruct; /* the capability description structure */
817 * OK. The general rule of thumb that we always should be getting a capability identifier
818 * string (see the grammar description). If it is followed by a comparison identifier, then
819 * there must follow an integer value we're comparing the capability to...
821 * Have the current token analyzed with that in mind...
823 for( i=0; i<(gint) strlen( scanner->value.v_identifier ); i++ )
825 gchar c = scanner->value.v_identifier[ i ];
827 if( (c == '=') || (c == '!') || (c == '<') || (c == '>') || (c == '~') )
832 * Here we go with the length of the capability identifier string.
833 * In the worst of cases, it is as long as the token identifier.
835 capability = g_strndup( scanner->value.v_identifier, i );
838 * OK. Is there a chance for comparison and value identifiers to follow?
839 * Note: checking against i+1 as this handles two cases: single character
840 * comparison operator and first of value's digits, which must always be
841 * there, or the two-character comparison operators.
843 if( (i + 1) < (gint) strlen( scanner->value.v_identifier ) )
846 * Yeah, indeed, it is the i-th character to start the identifier, then.
848 gchar c1 = scanner->value.v_identifier[ i + 0 ];
849 gchar c2 = scanner->value.v_identifier[ i + 1 ];
851 if( (c1 == '=') ) { i += 1; comparison = FG_EQUAL; } else
852 if( (c1 == '!') && (c2 == '=') ) { i += 2; comparison = FG_NOT_EQUAL; } else
853 if( (c1 == '<') && (c2 == '=') ) { i += 2; comparison = FG_LESS_OR_EQUAL; } else
854 if( (c1 == '>') && (c2 == '=') ) { i += 2; comparison = FG_MORE_OR_EQUAL; } else
855 if( (c1 == '<') ) { i += 1; comparison = FG_LESS; } else
856 if( (c1 == '>') ) { i += 1; comparison = FG_MORE; } else
857 if( (c1 == '~') ) { i += 1; comparison = FG_CLOSEST; } else
858 g_warning( "invalid comparison operator in token `%s'", scanner->value.v_identifier );
862 * Grab the value string that must follow the comparison operator...
864 if( comparison != FG_NONE && i < (gint) strlen( scanner->value.v_identifier ) )
865 valueString = strdup( scanner->value.v_identifier + i );
868 * If there was a value string, convert it to integer...
870 if( comparison != FG_NONE && strlen( valueString ) > 0 )
871 value = strtol( valueString, NULL, 0 );
874 * Now we need to match the capability string and its ID
876 for( i=0; g_Tokens[ i ]!=NULL; i++ )
878 if( strcmp( capability, g_Tokens[ i ] ) == 0 )
881 * Looks like we've found the one we were looking for
889 * Create a new capability description structure
891 capStruct = g_new0( SFG_Capability, 1 );
894 * Fill in the cap's values, as we have parsed it:
896 capStruct->capability = capID;
897 capStruct->comparison = comparison;
898 capStruct->value = value;
901 * Add the new capabaility to the caps list
903 caps = g_list_append( caps, capStruct );
906 * Clean up the local mess and keep rolling on
908 g_free( valueString );
909 g_free( capability );
914 * Now that we have converted the string into somewhat more machine-friendly
915 * form, proceed with matching the frame buffer configuration...
917 * The caps list could be passed to a function that would try finding the closest
918 * matching pixel format, visual, frame buffer configuration or whatever. It would
919 * be good to convert the glutInitDisplayMode() to use the same method.
922 g_message( "found %i capability preferences", g_list_length( caps ) );
924 g_message( "token `%s': cap: %i, com: %i, val: %i",
925 scanner->value.v_identifier,
926 capStruct->capability,
927 capStruct->comparison,
933 * Free the capabilities we have parsed
935 for( i=0; i<(gint) g_list_length( caps ); i++ )
936 g_free( g_list_nth( caps, i )->data );
939 * Destroy the capabilities list itself
944 * Free the lexical scanner now...
946 g_scanner_destroy( scanner );
950 #define NUM_TOKENS 28
951 static char* Tokens[] =
953 "alpha", "acca", "acc", "blue", "buffer", "conformant", "depth", "double", "green",
954 "index", "num", "red", "rgba", "rgb", "luminance", "stencil", "single", "stereo", "samples",
955 "slow", "win32pdf", "xvisual", "xstaticgray", "xgrayscale", "xstaticcolor", "xpseudocolor",
956 "xtruecolor", "xdirectcolor"
959 static int TokenLengths[] =
961 5, 4, 3, 4, 6, 10, 5, 6, 5,
962 5, 3, 3, 4, 3, 9, 7, 6, 6, 7,
963 4, 8, 7, 11, 10, 12, 12,
967 void FGAPIENTRY glutInitDisplayString( const char* displayMode )
969 int glut_state_flag = 0 ;
971 * Unpack a lot of options from a character string. The options are delimited by blanks or tabs.
974 int len = strlen ( displayMode ) ;
975 char *buffer = malloc ( (len+1) * sizeof(char) ) ;
976 memcpy ( buffer, displayMode, len ) ;
979 token = strtok ( buffer, " \t" ) ;
986 for ( i = 0; i < NUM_TOKENS; i++ )
988 if ( strncmp ( token, Tokens[i], TokenLengths[i] ) == 0 ) break ;
993 case 0 : /* "alpha": Alpha color buffer precision in bits */
994 glut_state_flag |= GLUT_ALPHA ; /* Somebody fix this for me! */
997 case 1 : /* "acca": Red, green, blue, and alpha accumulation buffer precision in bits */
1000 case 2 : /* "acc": Red, green, and blue accumulation buffer precision in bits with zero bits alpha */
1001 glut_state_flag |= GLUT_ACCUM ; /* Somebody fix this for me! */
1004 case 3 : /* "blue": Blue color buffer precision in bits */
1007 case 4 : /* "buffer": Number of bits in the color index color buffer */
1010 case 5 : /* "conformant": Boolean indicating if the frame buffer configuration is conformant or not */
1013 case 6 : /* "depth": Number of bits of precsion in the depth buffer */
1014 glut_state_flag |= GLUT_DEPTH ; /* Somebody fix this for me! */
1017 case 7 : /* "double": Boolean indicating if the color buffer is double buffered */
1018 glut_state_flag |= GLUT_DOUBLE ;
1021 case 8 : /* "green": Green color buffer precision in bits */
1024 case 9 : /* "index": Boolean if the color model is color index or not */
1025 glut_state_flag |= GLUT_INDEX ;
1028 case 10 : /* "num": A special capability name indicating where the value represents the Nth frame buffer configuration matching the description string */
1031 case 11 : /* "red": Red color buffer precision in bits */
1034 case 12 : /* "rgba": Number of bits of red, green, blue, and alpha in the RGBA color buffer */
1035 glut_state_flag |= GLUT_RGBA ; /* Somebody fix this for me! */
1038 case 13 : /* "rgb": Number of bits of red, green, and blue in the RGBA color buffer with zero bits alpha */
1039 glut_state_flag |= GLUT_RGB ; /* Somebody fix this for me! */
1042 case 14 : /* "luminance": Number of bits of red in the RGBA and zero bits of green, blue (alpha not specified) of color buffer precision */
1043 glut_state_flag |= GLUT_LUMINANCE ; /* Somebody fix this for me! */
1046 case 15 : /* "stencil": Number of bits in the stencil buffer */
1047 glut_state_flag |= GLUT_STENCIL ; /* Somebody fix this for me! */
1050 case 16 : /* "single": Boolean indicate the color buffer is single buffered */
1051 glut_state_flag |= GLUT_SINGLE ;
1054 case 17 : /* "stereo": Boolean indicating the color buffer supports OpenGL-style stereo */
1055 glut_state_flag |= GLUT_STEREO ;
1058 case 18 : /* "samples": Indicates the number of multisamples to use based on GLX's SGIS_multisample extension (for antialiasing) */
1059 glut_state_flag |= GLUT_MULTISAMPLE ; /* Somebody fix this for me! */
1062 case 19 : /* "slow": Boolean indicating if the frame buffer configuration is slow or not */
1065 case 20 : /* "win32pdf": matches the Win32 Pixel Format Descriptor by number */
1066 #ifdef TARGET_HOST_WIN32
1070 case 21 : /* "xvisual": matches the X visual ID by number */
1071 #ifdef TARGET_HOST_UNIX_X11
1075 case 22 : /* "xstaticgray": boolean indicating if the frame buffer configuration's X visual is of type StaticGray */
1076 #ifdef TARGET_HOST_UNIX_X11
1080 case 23 : /* "xgrayscale": boolean indicating if the frame buffer configuration's X visual is of type GrayScale */
1081 #ifdef TARGET_HOST_UNIX_X11
1085 case 24 : /* "xstaticcolor": boolean indicating if the frame buffer configuration's X visual is of type StaticColor */
1086 #ifdef TARGET_HOST_UNIX_X11
1090 case 25 : /* "xpseudocolor": boolean indicating if the frame buffer configuration's X visual is of type PseudoColor */
1091 #ifdef TARGET_HOST_UNIX_X11
1095 case 26 : /* "xtruecolor": boolean indicating if the frame buffer configuration's X visual is of type TrueColor */
1096 #ifdef TARGET_HOST_UNIX_X11
1100 case 27 : /* "xdirectcolor": boolean indicating if the frame buffer configuration's X visual is of type DirectColor */
1101 #ifdef TARGET_HOST_UNIX_X11
1105 case 28 : /* Unrecognized */
1106 printf ( "WARNING - Display string token not recognized: %s\n", token ) ;
1110 token = strtok ( NULL, " \t" ) ;
1116 * We will make use of this value when creating a new OpenGL context...
1118 fgState.DisplayMode = glut_state_flag;
1121 /*** END OF FILE ***/