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.
28 #define FREEGLUT_BUILDING_LIB
29 #include <GL/freeglut.h>
30 #include "freeglut_internal.h"
32 #if TARGET_HOST_POSIX_X11
33 #include <limits.h> /* LONG_MAX */
37 * TODO BEFORE THE STABLE RELEASE:
39 * fgDeinitialize() -- Win32's OK, X11 needs the OS-specific
40 * deinitialization done
41 * glutInitDisplayString() -- display mode string parsing
43 * Wouldn't it be cool to use gettext() for error messages? I just love
44 * bash saying "nie znaleziono pliku" instead of "file not found" :)
45 * Is gettext easily portable?
48 /* -- GLOBAL VARIABLES ----------------------------------------------------- */
51 * A structure pointed by g_pDisplay holds all information
52 * regarding the display, screen, root window etc.
54 SFG_Display fgDisplay;
57 * The settings for the current freeglut session
59 SFG_State fgState = { { -1, -1, GL_FALSE }, /* Position */
60 { 300, 300, GL_TRUE }, /* Size */
61 GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH, /* DisplayMode */
62 GL_FALSE, /* Initialised */
63 GLUT_TRY_DIRECT_CONTEXT, /* DirectContext */
64 GL_FALSE, /* ForceIconic */
65 GL_FALSE, /* UseCurrentContext */
66 GL_FALSE, /* GLDebugSwitch */
67 GL_FALSE, /* XSyncSwitch */
68 GLUT_KEY_REPEAT_ON, /* KeyRepeat */
69 INVALID_MODIFIERS, /* Modifiers */
74 { NULL, NULL }, /* Timers */
75 { NULL, NULL }, /* FreeTimers */
76 NULL, /* IdleCallback */
78 NULL, /* MenuStateCallback */
79 NULL, /* MenuStatusCallback */
80 { 640, 480, GL_TRUE }, /* GameModeSize */
81 16, /* GameModeDepth */
82 72, /* GameModeRefresh */
83 GLUT_ACTION_EXIT, /* ActionOnWindowClose */
84 GLUT_EXEC_STATE_INIT, /* ExecState */
85 NULL, /* ProgramName */
86 GL_FALSE, /* JoysticksInitialised */
87 0, /* NumActiveJoysticks */
88 GL_FALSE, /* InputDevsInitialised */
89 0, /* MouseWheelTicks */
90 1, /* AuxiliaryBufferNumber */
95 0, /* ContextProfile */
97 NULL /* WarningFunc */
101 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
103 #if TARGET_HOST_POSIX_X11
105 /* Return the atom associated with "name". */
106 static Atom fghGetAtom(const char * name)
108 return XInternAtom(fgDisplay.Display, name, False);
112 * Check if "property" is set on "window". The property's values are returned
113 * through "data". If the property is set and is of type "type", return the
114 * number of elements in "data". Return zero otherwise. In both cases, use
115 * "Xfree()" to free "data".
117 static int fghGetWindowProperty(Window window,
120 unsigned char ** data)
123 * Caller always has to use "Xfree()" to free "data", since
124 * "XGetWindowProperty() always allocates one extra byte in prop_return
125 * [i.e. "data"] (even if the property is zero length) [..]".
128 int status; /* Returned by "XGetWindowProperty". */
131 int temp_format; /* Not used. */
132 unsigned long number_of_elements;
133 unsigned long temp_bytes_after; /* Not used. */
136 status = XGetWindowProperty(fgDisplay.Display,
149 FREEGLUT_INTERNAL_ERROR_EXIT(status == Success,
150 "XGetWindowProperty failled",
151 "fghGetWindowProperty");
153 if (type_returned != type)
155 number_of_elements = 0;
158 return number_of_elements;
161 /* Check if the window manager is NET WM compliant. */
162 static int fghNetWMSupported(void)
165 Window ** window_ptr_1;
167 int number_of_windows;
168 int net_wm_supported;
171 net_wm_supported = 0;
173 wm_check = fghGetAtom("_NET_SUPPORTING_WM_CHECK");
174 window_ptr_1 = malloc(sizeof(Window *));
177 * Check that the window manager has set this property on the root window.
178 * The property must be the ID of a child window.
180 number_of_windows = fghGetWindowProperty(fgDisplay.RootWindow,
183 (unsigned char **) window_ptr_1);
184 if (number_of_windows == 1)
186 Window ** window_ptr_2;
188 window_ptr_2 = malloc(sizeof(Window *));
190 /* Check that the window has the same property set to the same value. */
191 number_of_windows = fghGetWindowProperty(**window_ptr_1,
194 (unsigned char **) window_ptr_2);
195 if ((number_of_windows == 1) && (**window_ptr_1 == **window_ptr_2))
197 /* NET WM compliant */
198 net_wm_supported = 1;
201 XFree(*window_ptr_2);
205 XFree(*window_ptr_1);
208 return net_wm_supported;
211 /* Check if "hint" is present in "property" for "window". */
212 int fgHintPresent(Window window, Atom property, Atom hint)
221 number_of_atoms = fghGetWindowProperty(window,
224 (unsigned char **) &atoms);
225 for (i = 0; i < number_of_atoms; i++)
227 if (atoms[i] == hint)
238 #endif /* TARGET_HOST_POSIX_X11 */
242 * A call to this function should initialize all the display stuff...
244 static void fghInitialize( const char* displayName )
246 #if TARGET_HOST_POSIX_X11
247 fgDisplay.Display = XOpenDisplay( displayName );
249 if( fgDisplay.Display == NULL )
250 fgError( "failed to open display '%s'", XDisplayName( displayName ) );
252 if( !glXQueryExtension( fgDisplay.Display, NULL, NULL ) )
253 fgError( "OpenGL GLX extension not supported by display '%s'",
254 XDisplayName( displayName ) );
256 fgDisplay.Screen = DefaultScreen( fgDisplay.Display );
257 fgDisplay.RootWindow = RootWindow(
262 fgDisplay.ScreenWidth = DisplayWidth(
266 fgDisplay.ScreenHeight = DisplayHeight(
271 fgDisplay.ScreenWidthMM = DisplayWidthMM(
275 fgDisplay.ScreenHeightMM = DisplayHeightMM(
280 fgDisplay.Connection = ConnectionNumber( fgDisplay.Display );
282 /* Create the window deletion atom */
283 fgDisplay.DeleteWindow = fghGetAtom("WM_DELETE_WINDOW");
285 /* Create the state and full screen atoms */
286 fgDisplay.State = None;
287 fgDisplay.StateFullScreen = None;
289 if (fghNetWMSupported())
291 const Atom supported = fghGetAtom("_NET_SUPPORTED");
292 const Atom state = fghGetAtom("_NET_WM_STATE");
294 /* Check if the state hint is supported. */
295 if (fgHintPresent(fgDisplay.RootWindow, supported, state))
297 const Atom full_screen = fghGetAtom("_NET_WM_STATE_FULLSCREEN");
299 fgDisplay.State = state;
301 /* Check if the window manager supports full screen. */
302 /** Check "_NET_WM_ALLOWED_ACTIONS" on our window instead? **/
303 if (fgHintPresent(fgDisplay.RootWindow, supported, full_screen))
305 fgDisplay.StateFullScreen = full_screen;
310 #elif TARGET_HOST_MS_WINDOWS
315 /* What we need to do is to initialize the fgDisplay global structure here. */
316 fgDisplay.Instance = GetModuleHandle( NULL );
317 fgDisplay.DisplayName= displayName ? strdup(displayName) : 0 ;
318 atom = GetClassInfo( fgDisplay.Instance, _T("FREEGLUT"), &wc );
322 ZeroMemory( &wc, sizeof(WNDCLASS) );
325 * Each of the windows should have its own device context, and we
326 * want redraw events during Vertical and Horizontal Resizes by
329 * XXX Old code had "| CS_DBCLCKS" commented out. Plans for the
330 * XXX future? Dead-end idea?
332 wc.lpfnWndProc = fgWindowProc;
335 wc.hInstance = fgDisplay.Instance;
336 wc.hIcon = LoadIcon( fgDisplay.Instance, _T("GLUT_ICON") );
338 #if defined(_WIN32_WCE)
339 wc.style = CS_HREDRAW | CS_VREDRAW;
341 wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
343 wc.hIcon = LoadIcon( NULL, IDI_WINLOGO );
346 wc.hCursor = LoadCursor( NULL, IDC_ARROW );
347 wc.hbrBackground = NULL;
348 wc.lpszMenuName = NULL;
349 wc.lpszClassName = _T("FREEGLUT");
351 /* Register the window class */
352 atom = RegisterClass( &wc );
353 FREEGLUT_INTERNAL_ERROR_EXIT ( atom, "Window Class Not Registered", "fghInitialize" );
356 /* The screen dimensions can be obtained via GetSystemMetrics() calls */
357 fgDisplay.ScreenWidth = GetSystemMetrics( SM_CXSCREEN );
358 fgDisplay.ScreenHeight = GetSystemMetrics( SM_CYSCREEN );
361 HWND desktop = GetDesktopWindow( );
362 HDC context = GetDC( desktop );
364 fgDisplay.ScreenWidthMM = GetDeviceCaps( context, HORZSIZE );
365 fgDisplay.ScreenHeightMM = GetDeviceCaps( context, VERTSIZE );
367 ReleaseDC( desktop, context );
369 /* If we have a DisplayName try to use it for metrics */
370 if( fgDisplay.DisplayName )
372 HDC context = CreateDC(fgDisplay.DisplayName,0,0,0);
375 fgDisplay.ScreenWidth = GetDeviceCaps( context, HORZRES );
376 fgDisplay.ScreenHeight = GetDeviceCaps( context, VERTRES );
377 fgDisplay.ScreenWidthMM = GetDeviceCaps( context, HORZSIZE );
378 fgDisplay.ScreenHeightMM = GetDeviceCaps( context, VERTSIZE );
382 fgWarning("fghInitialize: "
383 "CreateDC failed, Screen size info may be incorrect\n"
384 "This is quite likely caused by a bad '-display' parameter");
387 /* Set the timer granularity to 1 ms */
388 timeBeginPeriod ( 1 );
392 fgState.Initialised = GL_TRUE;
394 /* Avoid registering atexit callback on Win32 as it results in an access
395 * violation due to calling into a module which has been unloaded. */
396 #ifndef TARGET_HOST_MS_WINDOWS
397 atexit(fgDeinitialize);
400 /* InputDevice uses GlutTimerFunc(), so fgState.Initialised must be TRUE */
401 fgInitialiseInputDevices();
405 * Perform the freeglut deinitialization...
407 void fgDeinitialize( void )
411 if( !fgState.Initialised )
416 /* If there was a menu created, destroy the rendering context */
417 if( fgStructure.MenuContext )
419 #if TARGET_HOST_POSIX_X11
420 /* Note that the MVisualInfo is not owned by the MenuContext! */
421 glXDestroyContext( fgDisplay.Display, fgStructure.MenuContext->MContext );
423 free( fgStructure.MenuContext );
424 fgStructure.MenuContext = NULL;
427 fgDestroyStructure( );
429 while( ( timer = fgState.Timers.First) )
431 fgListRemove( &fgState.Timers, &timer->Node );
435 while( ( timer = fgState.FreeTimers.First) )
437 fgListRemove( &fgState.FreeTimers, &timer->Node );
441 #if !defined(_WIN32_WCE)
442 if ( fgState.JoysticksInitialised )
445 if ( fgState.InputDevsInitialised )
446 fgInputDeviceClose( );
447 #endif /* !defined(_WIN32_WCE) */
448 fgState.JoysticksInitialised = GL_FALSE;
449 fgState.InputDevsInitialised = GL_FALSE;
451 fgState.MouseWheelTicks = 0;
453 fgState.MajorVersion = 1;
454 fgState.MinorVersion = 0;
455 fgState.ContextFlags = 0;
456 fgState.ContextProfile = 0;
458 fgState.Initialised = GL_FALSE;
460 fgState.Position.X = -1;
461 fgState.Position.Y = -1;
462 fgState.Position.Use = GL_FALSE;
464 fgState.Size.X = 300;
465 fgState.Size.Y = 300;
466 fgState.Size.Use = GL_TRUE;
468 fgState.DisplayMode = GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH;
470 fgState.DirectContext = GLUT_TRY_DIRECT_CONTEXT;
471 fgState.ForceIconic = GL_FALSE;
472 fgState.UseCurrentContext = GL_FALSE;
473 fgState.GLDebugSwitch = GL_FALSE;
474 fgState.XSyncSwitch = GL_FALSE;
475 fgState.ActionOnWindowClose = GLUT_ACTION_EXIT;
476 fgState.ExecState = GLUT_EXEC_STATE_INIT;
478 fgState.KeyRepeat = GLUT_KEY_REPEAT_ON;
479 fgState.Modifiers = INVALID_MODIFIERS;
481 fgState.GameModeSize.X = 640;
482 fgState.GameModeSize.Y = 480;
483 fgState.GameModeDepth = 16;
484 fgState.GameModeRefresh = 72;
486 fgListInit( &fgState.Timers );
487 fgListInit( &fgState.FreeTimers );
489 fgState.IdleCallback = NULL;
490 fgState.MenuStateCallback = ( FGCBMenuState )NULL;
491 fgState.MenuStatusCallback = ( FGCBMenuStatus )NULL;
493 fgState.SwapCount = 0;
494 fgState.SwapTime = 0;
495 fgState.FPSInterval = 0;
497 if( fgState.ProgramName )
499 free( fgState.ProgramName );
500 fgState.ProgramName = NULL;
503 #if TARGET_HOST_POSIX_X11
506 * Make sure all X-client data we have created will be destroyed on
509 XSetCloseDownMode( fgDisplay.Display, DestroyAll );
512 * Close the display connection, destroying all windows we have
515 XCloseDisplay( fgDisplay.Display );
517 #elif TARGET_HOST_MS_WINDOWS
518 if( fgDisplay.DisplayName )
520 free( fgDisplay.DisplayName );
521 fgDisplay.DisplayName = NULL;
524 /* Reset the timer granularity */
529 fgState.Initialised = GL_FALSE;
533 * Everything inside the following #ifndef is copied from the X sources.
536 #if TARGET_HOST_MS_WINDOWS
540 Copyright 1985, 1986, 1987,1998 The Open Group
542 Permission to use, copy, modify, distribute, and sell this software and its
543 documentation for any purpose is hereby granted without fee, provided that
544 the above copyright notice appear in all copies and that both that
545 copyright notice and this permission notice appear in supporting
548 The above copyright notice and this permission notice shall be included
549 in all copies or substantial portions of the Software.
551 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
552 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
553 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
554 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
555 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
556 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
557 OTHER DEALINGS IN THE SOFTWARE.
559 Except as contained in this notice, the name of The Open Group shall
560 not be used in advertising or otherwise to promote the sale, use or
561 other dealings in this Software without prior written authorization
566 #define NoValue 0x0000
567 #define XValue 0x0001
568 #define YValue 0x0002
569 #define WidthValue 0x0004
570 #define HeightValue 0x0008
571 #define AllValues 0x000F
572 #define XNegative 0x0010
573 #define YNegative 0x0020
576 * XParseGeometry parses strings of the form
577 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
578 * width, height, xoffset, and yoffset are unsigned integers.
579 * Example: "=80x24+300-49"
580 * The equal sign is optional.
581 * It returns a bitmask that indicates which of the four values
582 * were actually found in the string. For each value found,
583 * the corresponding argument is updated; for each value
584 * not found, the corresponding argument is left unchanged.
588 ReadInteger(char *string, char **NextString)
590 register int Result = 0;
595 else if (*string == '-')
600 for (; (*string >= '0') && (*string <= '9'); string++)
602 Result = (Result * 10) + (*string - '0');
604 *NextString = string;
611 static int XParseGeometry (
615 unsigned int *width, /* RETURN */
616 unsigned int *height) /* RETURN */
619 register char *strind;
620 unsigned int tempWidth = 0, tempHeight = 0;
621 int tempX = 0, tempY = 0;
624 if ( (string == NULL) || (*string == '\0'))
627 string++; /* ignore possible '=' at beg of geometry spec */
629 strind = (char *)string;
630 if (*strind != '+' && *strind != '-' && *strind != 'x') {
631 tempWidth = ReadInteger(strind, &nextCharacter);
632 if (strind == nextCharacter)
634 strind = nextCharacter;
638 if (*strind == 'x' || *strind == 'X') {
640 tempHeight = ReadInteger(strind, &nextCharacter);
641 if (strind == nextCharacter)
643 strind = nextCharacter;
647 if ((*strind == '+') || (*strind == '-')) {
648 if (*strind == '-') {
650 tempX = -ReadInteger(strind, &nextCharacter);
651 if (strind == nextCharacter)
653 strind = nextCharacter;
659 tempX = ReadInteger(strind, &nextCharacter);
660 if (strind == nextCharacter)
662 strind = nextCharacter;
665 if ((*strind == '+') || (*strind == '-')) {
666 if (*strind == '-') {
668 tempY = -ReadInteger(strind, &nextCharacter);
669 if (strind == nextCharacter)
671 strind = nextCharacter;
677 tempY = ReadInteger(strind, &nextCharacter);
678 if (strind == nextCharacter)
680 strind = nextCharacter;
686 /* If strind isn't at the end of the string the it's an invalid
687 geometry specification. */
689 if (*strind != '\0') return 0;
695 if (mask & WidthValue)
697 if (mask & HeightValue)
698 *height = tempHeight;
703 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
706 * Perform initialization. This usually happens on the program startup
707 * and restarting after glutMainLoop termination...
709 void FGAPIENTRY glutInit( int* pargc, char** argv )
711 char* displayName = NULL;
712 char* geometry = NULL;
713 int i, j, argc = *pargc;
715 if( fgState.Initialised )
716 fgError( "illegal glutInit() reinitialization attempt" );
718 if (pargc && *pargc && argv && *argv && **argv)
720 fgState.ProgramName = strdup (*argv);
722 if( !fgState.ProgramName )
723 fgError ("Could not allocate space for the program's name.");
726 fgCreateStructure( );
729 fgState.Time = fgSystemTime();
731 /* check if GLUT_FPS env var is set */
734 const char *fps = getenv( "GLUT_FPS" );
739 sscanf( fps, "%d", &interval );
742 fgState.FPSInterval = 5000; /* 5000 millisecond default */
744 fgState.FPSInterval = interval;
748 displayName = getenv( "DISPLAY" );
750 for( i = 1; i < argc; i++ )
752 if( strcmp( argv[ i ], "-display" ) == 0 )
755 fgError( "-display parameter must be followed by display name" );
757 displayName = argv[ i ];
759 argv[ i - 1 ] = NULL;
763 else if( strcmp( argv[ i ], "-geometry" ) == 0 )
766 fgError( "-geometry parameter must be followed by window "
767 "geometry settings" );
769 geometry = argv[ i ];
771 argv[ i - 1 ] = NULL;
775 else if( strcmp( argv[ i ], "-direct" ) == 0)
777 if( fgState.DirectContext == GLUT_FORCE_INDIRECT_CONTEXT )
778 fgError( "parameters ambiguity, -direct and -indirect "
779 "cannot be both specified" );
781 fgState.DirectContext = GLUT_FORCE_DIRECT_CONTEXT;
785 else if( strcmp( argv[ i ], "-indirect" ) == 0 )
787 if( fgState.DirectContext == GLUT_FORCE_DIRECT_CONTEXT )
788 fgError( "parameters ambiguity, -direct and -indirect "
789 "cannot be both specified" );
791 fgState.DirectContext = GLUT_FORCE_INDIRECT_CONTEXT;
795 else if( strcmp( argv[ i ], "-iconic" ) == 0 )
797 fgState.ForceIconic = GL_TRUE;
801 else if( strcmp( argv[ i ], "-gldebug" ) == 0 )
803 fgState.GLDebugSwitch = GL_TRUE;
807 else if( strcmp( argv[ i ], "-sync" ) == 0 )
809 fgState.XSyncSwitch = GL_TRUE;
815 /* Compact {argv}. */
816 for( i = j = 1; i < *pargc; i++, j++ )
818 /* Guaranteed to end because there are "*pargc" arguments left */
819 while ( argv[ j ] == NULL )
822 argv[ i ] = argv[ j ];
825 #endif /* _WIN32_WCE */
828 * Have the display created now. If there wasn't a "-display"
829 * in the program arguments, we will use the DISPLAY environment
830 * variable for opening the X display (see code above):
832 fghInitialize( displayName );
835 * Geometry parsing deffered until here because we may need the screen
841 unsigned int parsedWidth, parsedHeight;
842 int mask = XParseGeometry( geometry,
843 &fgState.Position.X, &fgState.Position.Y,
844 &parsedWidth, &parsedHeight );
845 /* TODO: Check for overflow? */
846 fgState.Size.X = parsedWidth;
847 fgState.Size.Y = parsedHeight;
849 if( (mask & (WidthValue|HeightValue)) == (WidthValue|HeightValue) )
850 fgState.Size.Use = GL_TRUE;
852 if( mask & XNegative )
853 fgState.Position.X += fgDisplay.ScreenWidth - fgState.Size.X;
855 if( mask & YNegative )
856 fgState.Position.Y += fgDisplay.ScreenHeight - fgState.Size.Y;
858 if( (mask & (XValue|YValue)) == (XValue|YValue) )
859 fgState.Position.Use = GL_TRUE;
863 #if TARGET_HOST_MS_WINDOWS
864 void (__cdecl *__glutExitFunc)( int return_value ) = NULL;
866 void FGAPIENTRY __glutInitWithExit( int *pargc, char **argv, void (__cdecl *exit_function)(int) )
868 __glutExitFunc = exit_function;
869 glutInit(pargc, argv);
874 * Undoes all the "glutInit" stuff
876 void FGAPIENTRY glutExit ( void )
882 * Sets the default initial window position for new windows
884 void FGAPIENTRY glutInitWindowPosition( int x, int y )
886 fgState.Position.X = x;
887 fgState.Position.Y = y;
889 if( ( x >= 0 ) && ( y >= 0 ) )
890 fgState.Position.Use = GL_TRUE;
892 fgState.Position.Use = GL_FALSE;
896 * Sets the default initial window size for new windows
898 void FGAPIENTRY glutInitWindowSize( int width, int height )
900 fgState.Size.X = width;
901 fgState.Size.Y = height;
903 if( ( width > 0 ) && ( height > 0 ) )
904 fgState.Size.Use = GL_TRUE;
906 fgState.Size.Use = GL_FALSE;
910 * Sets the default display mode for all new windows
912 void FGAPIENTRY glutInitDisplayMode( unsigned int displayMode )
914 /* We will make use of this value when creating a new OpenGL context... */
915 fgState.DisplayMode = displayMode;
919 /* -- INIT DISPLAY STRING PARSING ------------------------------------------ */
921 static char* Tokens[] =
923 "alpha", "acca", "acc", "blue", "buffer", "conformant", "depth", "double",
924 "green", "index", "num", "red", "rgba", "rgb", "luminance", "stencil",
925 "single", "stereo", "samples", "slow", "win32pdf", "win32pfd", "xvisual",
926 "xstaticgray", "xgrayscale", "xstaticcolor", "xpseudocolor",
927 "xtruecolor", "xdirectcolor",
928 "xstaticgrey", "xgreyscale", "xstaticcolour", "xpseudocolour",
929 "xtruecolour", "xdirectcolour", "borderless", "aux"
931 #define NUM_TOKENS (sizeof(Tokens) / sizeof(*Tokens))
933 void FGAPIENTRY glutInitDisplayString( const char* displayMode )
935 int glut_state_flag = 0 ;
937 * Unpack a lot of options from a character string. The options are
938 * delimited by blanks or tabs.
941 size_t len = strlen ( displayMode );
942 char *buffer = (char *)malloc ( (len+1) * sizeof(char) );
943 memcpy ( buffer, displayMode, len );
946 token = strtok ( buffer, " \t" );
950 /* Process this token */
953 /* Temporary fix: Ignore any length specifications and at least
954 * process the basic token
955 * TODO: Fix this permanently
957 size_t cleanlength = strcspn ( token, "=<>~!" );
959 for ( i = 0; i < NUM_TOKENS; i++ )
961 if ( strncmp ( token, Tokens[i], cleanlength ) == 0 ) break ;
966 case 0 : /* "alpha": Alpha color buffer precision in bits */
967 glut_state_flag |= GLUT_ALPHA ; /* Somebody fix this for me! */
970 case 1 : /* "acca": Red, green, blue, and alpha accumulation buffer
974 case 2 : /* "acc": Red, green, and blue accumulation buffer precision
975 in bits with zero bits alpha */
976 glut_state_flag |= GLUT_ACCUM ; /* Somebody fix this for me! */
979 case 3 : /* "blue": Blue color buffer precision in bits */
982 case 4 : /* "buffer": Number of bits in the color index color buffer
986 case 5 : /* "conformant": Boolean indicating if the frame buffer
987 configuration is conformant or not */
990 case 6 : /* "depth": Number of bits of precsion in the depth buffer */
991 glut_state_flag |= GLUT_DEPTH ; /* Somebody fix this for me! */
994 case 7 : /* "double": Boolean indicating if the color buffer is
996 glut_state_flag |= GLUT_DOUBLE ;
999 case 8 : /* "green": Green color buffer precision in bits */
1002 case 9 : /* "index": Boolean if the color model is color index or not
1004 glut_state_flag |= GLUT_INDEX ;
1007 case 10 : /* "num": A special capability name indicating where the
1008 value represents the Nth frame buffer configuration
1009 matching the description string */
1012 case 11 : /* "red": Red color buffer precision in bits */
1015 case 12 : /* "rgba": Number of bits of red, green, blue, and alpha in
1016 the RGBA color buffer */
1017 glut_state_flag |= GLUT_RGBA ; /* Somebody fix this for me! */
1020 case 13 : /* "rgb": Number of bits of red, green, and blue in the
1021 RGBA color buffer with zero bits alpha */
1022 glut_state_flag |= GLUT_RGB ; /* Somebody fix this for me! */
1025 case 14 : /* "luminance": Number of bits of red in the RGBA and zero
1026 bits of green, blue (alpha not specified) of color buffer
1028 glut_state_flag |= GLUT_LUMINANCE ; /* Somebody fix this for me! */
1031 case 15 : /* "stencil": Number of bits in the stencil buffer */
1032 glut_state_flag |= GLUT_STENCIL; /* Somebody fix this for me! */
1035 case 16 : /* "single": Boolean indicate the color buffer is single
1037 glut_state_flag |= GLUT_SINGLE ;
1040 case 17 : /* "stereo": Boolean indicating the color buffer supports
1041 OpenGL-style stereo */
1042 glut_state_flag |= GLUT_STEREO ;
1045 case 18 : /* "samples": Indicates the number of multisamples to use
1046 based on GLX's SGIS_multisample extension (for
1048 glut_state_flag |= GLUT_MULTISAMPLE ; /*Somebody fix this for me!*/
1051 case 19 : /* "slow": Boolean indicating if the frame buffer
1052 configuration is slow or not */
1055 case 20 : /* "win32pdf": (incorrect spelling but was there before */
1056 case 21 : /* "win32pfd": matches the Win32 Pixel Format Descriptor by
1058 #if TARGET_HOST_MS_WINDOWS
1062 case 22 : /* "xvisual": matches the X visual ID by number */
1063 #if TARGET_HOST_POSIX_X11
1067 case 23 : /* "xstaticgray": */
1068 case 29 : /* "xstaticgrey": boolean indicating if the frame buffer
1069 configuration's X visual is of type StaticGray */
1070 #if TARGET_HOST_POSIX_X11
1074 case 24 : /* "xgrayscale": */
1075 case 30 : /* "xgreyscale": boolean indicating if the frame buffer
1076 configuration's X visual is of type GrayScale */
1077 #if TARGET_HOST_POSIX_X11
1081 case 25 : /* "xstaticcolor": */
1082 case 31 : /* "xstaticcolour": boolean indicating if the frame buffer
1083 configuration's X visual is of type StaticColor */
1084 #if TARGET_HOST_POSIX_X11
1088 case 26 : /* "xpseudocolor": */
1089 case 32 : /* "xpseudocolour": boolean indicating if the frame buffer
1090 configuration's X visual is of type PseudoColor */
1091 #if TARGET_HOST_POSIX_X11
1095 case 27 : /* "xtruecolor": */
1096 case 33 : /* "xtruecolour": boolean indicating if the frame buffer
1097 configuration's X visual is of type TrueColor */
1098 #if TARGET_HOST_POSIX_X11
1102 case 28 : /* "xdirectcolor": */
1103 case 34 : /* "xdirectcolour": boolean indicating if the frame buffer
1104 configuration's X visual is of type DirectColor */
1105 #if TARGET_HOST_POSIX_X11
1109 case 35 : /* "borderless": windows should not have borders */
1110 #if TARGET_HOST_POSIX_X11
1114 case 36 : /* "aux": some number of aux buffers */
1115 glut_state_flag |= GLUT_AUX;
1118 case 37 : /* Unrecognized */
1119 fgWarning ( "WARNING - Display string token not recognized: %s",
1124 token = strtok ( NULL, " \t" );
1129 /* We will make use of this value when creating a new OpenGL context... */
1130 fgState.DisplayMode = glut_state_flag;
1133 /* -- SETTING OPENGL 3.0 CONTEXT CREATION PARAMETERS ---------------------- */
1135 void FGAPIENTRY glutInitContextVersion( int majorVersion, int minorVersion )
1137 /* We will make use of these valuse when creating a new OpenGL context... */
1138 fgState.MajorVersion = majorVersion;
1139 fgState.MinorVersion = minorVersion;
1143 void FGAPIENTRY glutInitContextFlags( int flags )
1145 /* We will make use of this value when creating a new OpenGL context... */
1146 fgState.ContextFlags = flags;
1149 void FGAPIENTRY glutInitContextProfile( int profile )
1151 /* We will make use of this value when creating a new OpenGL context... */
1152 fgState.ContextProfile = profile;
1155 /* -------------- User Defined Error/Warning Handler Support -------------- */
1158 * Sets the user error handler (note the use of va_list for the args to the fmt)
1160 void FGAPIENTRY glutInitErrorFunc( void (* vfgError) ( const char *fmt, va_list ap ) )
1162 /* This allows user programs to handle freeglut errors */
1163 fgState.ErrorFunc = vfgError;
1167 * Sets the user warning handler (note the use of va_list for the args to the fmt)
1169 void FGAPIENTRY glutInitWarningFunc( void (* vfgWarning) ( const char *fmt, va_list ap ) )
1171 /* This allows user programs to handle freeglut warnings */
1172 fgState.WarningFunc = vfgWarning;
1175 /*** END OF FILE ***/