/* * This private function creates a menu and adds it to the menus list */ SFG_Menu* fgCreateMenu( FGCBMenu menuCallback ) { int x = 100, y = 100, w = 1, h = 1; SFG_Window *current_window = fgStructure.CurrentWindow; /* Have the menu object created */ SFG_Menu* menu = (SFG_Menu *)calloc( sizeof(SFG_Menu), 1 ); menu->ParentWindow = NULL; /* Create a window for the menu to reside in. */ fgCreateWindow( NULL, "freeglut menu", GL_TRUE, x, y, GL_TRUE, w, h, GL_FALSE, GL_TRUE ); menu->Window = fgStructure.CurrentWindow; glutDisplayFunc( fgDisplayMenu ); glutHideWindow( ); /* Hide the window for now */ fgSetWindow( current_window ); /* Initialize the object properties: */ menu->ID = ++fgStructure.MenuID; menu->Callback = menuCallback; menu->ActiveEntry = NULL; fgListInit( &menu->Entries ); fgListAppend( &fgStructure.Menus, &menu->Node ); /* Newly created menus implicitly become current ones */ fgStructure.CurrentMenu = menu; return menu; }
/* * This function should be called on glutInit(). It will prepare the internal * structure of freeglut to be used in the application. The structure will be * destroyed using fgDestroyStructure() on glutMainLoop() return. In that * case further use of freeglut should be preceeded with a glutInit() call. */ void fgCreateStructure( void ) { /* * We will be needing two lists: the first containing windows, * and the second containing the user-defined menus. * Also, no current window/menu is set, as none has been created yet. */ fgListInit(&fgStructure.Windows); fgListInit(&fgStructure.Menus); fgListInit(&fgStructure.WindowsToDestroy); fgStructure.CurrentWindow = NULL; fgStructure.CurrentMenu = NULL; fgStructure.MenuContext = NULL; fgStructure.GameModeWindow = NULL; fgStructure.WindowID = 0; fgStructure.MenuID = 0; }
/* * This private function creates, opens and adds to the hierarchy * a freeglut window complete with OpenGL context and stuff... * * If parent is set to NULL, the window created will be a topmost one. */ SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title, GLboolean positionUse, int x, int y, GLboolean sizeUse, int w, int h, GLboolean gameMode, GLboolean isMenu ) { /* Have the window object created */ SFG_Window *window = (SFG_Window *)calloc( sizeof(SFG_Window), 1 ); #if TARGET_HOST_UNIX_X11 window->Window.FBConfig = NULL; #endif fghClearCallBacks( window ); /* Initialize the object properties */ window->ID = ++fgStructure.WindowID; #if TARGET_HOST_POSIX_X11 window->State.OldHeight = window->State.OldWidth = -1; #endif fgListInit( &window->Children ); if( parent ) { fgListAppend( &parent->Children, &window->Node ); window->Parent = parent; } else fgListAppend( &fgStructure.Windows, &window->Node ); /* Set the default mouse cursor and reset the modifiers value */ window->State.Cursor = GLUT_CURSOR_INHERIT; window->IsMenu = isMenu; window->State.IgnoreKeyRepeat = GL_FALSE; window->State.KeyRepeating = GL_FALSE; window->State.IsFullscreen = GL_FALSE; /* * Open the window now. The fgOpenWindow() function is system * dependant, and resides in freeglut_window.c. Uses fgState. */ fgOpenWindow( window, title, positionUse, x, y, sizeUse, w, h, gameMode, (GLboolean)(parent ? GL_TRUE : GL_FALSE) ); return window; }
/* * This private function creates, opens and adds to the hierarchy * a freeglut window complete with OpenGL context and stuff... * * If parent is set to NULL, the window created will be a topmost one. */ SFG_Window* fgCreateWindow( SFG_Window* parent, const char* title, GLboolean positionUse, int x, int y, GLboolean sizeUse, int w, int h, GLboolean gameMode, GLboolean isMenu ) { /* Have the window object created */ SFG_Window *window = (SFG_Window *)calloc( 1, sizeof(SFG_Window) ); fgPlatformCreateWindow ( window ); fghClearCallBacks( window ); SET_WCB( *window, Reshape, fghDefaultReshape); /* Initialize the object properties */ window->ID = ++fgStructure.WindowID; fgListInit( &window->Children ); if( parent ) { fgListAppend( &parent->Children, &window->Node ); window->Parent = parent; } else fgListAppend( &fgStructure.Windows, &window->Node ); /* Set the default mouse cursor */ window->State.Cursor = GLUT_CURSOR_INHERIT; /* Mark window as menu if a menu is to be created */ window->IsMenu = isMenu; /* * Open the window now. The fgOpenWindow() function is system * dependant, and resides in freeglut_window.c. Uses fgState. */ fgOpenWindow( window, title, positionUse, x, y, sizeUse, w, h, gameMode, (GLboolean)(parent ? GL_TRUE : GL_FALSE) ); return window; }
/* * Perform the freeglut deinitialization... */ void fgDeinitialize( void ) { SFG_Timer *timer; if( !fgState.Initialised ) { return; } /* If we're in game mode, we want to leave game mode */ if( fgStructure.GameModeWindow ) { glutLeaveGameMode(); } /* If there was a menu created, destroy the rendering context */ if( fgStructure.MenuContext ) { fgPlatformDestroyContext (fgDisplay.pDisplay, fgStructure.MenuContext->MContext ); free( fgStructure.MenuContext ); fgStructure.MenuContext = NULL; } fgDestroyStructure( ); while( ( timer = fgState.Timers.First) ) { fgListRemove( &fgState.Timers, &timer->Node ); free( timer ); } while( ( timer = fgState.FreeTimers.First) ) { fgListRemove( &fgState.FreeTimers, &timer->Node ); free( timer ); } fgPlatformDeinitialiseInputDevices (); fgState.MouseWheelTicks = 0; fgState.MajorVersion = 1; fgState.MinorVersion = 0; fgState.ContextFlags = 0; fgState.ContextProfile = 0; fgState.Initialised = GL_FALSE; fgState.Position.X = -1; fgState.Position.Y = -1; fgState.Position.Use = GL_FALSE; fgState.Size.X = 300; fgState.Size.Y = 300; fgState.Size.Use = GL_TRUE; fgState.DisplayMode = GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH; fgState.DirectContext = GLUT_TRY_DIRECT_CONTEXT; fgState.ForceIconic = GL_FALSE; fgState.UseCurrentContext = GL_FALSE; fgState.GLDebugSwitch = GL_FALSE; fgState.XSyncSwitch = GL_FALSE; fgState.ActionOnWindowClose = GLUT_ACTION_EXIT; fgState.ExecState = GLUT_EXEC_STATE_INIT; fgState.KeyRepeat = GLUT_KEY_REPEAT_ON; fgState.Modifiers = INVALID_MODIFIERS; fgState.GameModeSize.X = -1; fgState.GameModeSize.Y = -1; fgState.GameModeDepth = -1; fgState.GameModeRefresh = -1; fgListInit( &fgState.Timers ); fgListInit( &fgState.FreeTimers ); fgState.IdleCallback = NULL; fgState.MenuStateCallback = ( FGCBMenuState )NULL; fgState.MenuStatusCallback = ( FGCBMenuStatus )NULL; fgState.SwapCount = 0; fgState.SwapTime = 0; fgState.FPSInterval = 0; if( fgState.ProgramName ) { free( fgState.ProgramName ); fgState.ProgramName = NULL; } fgPlatformCloseDisplay (); fgState.Initialised = GL_FALSE; }
/* * Perform the freeglut deinitialization... */ void fgDeinitialize( void ) { SFG_Timer *timer; if( !fgState.Initialised ) { fgWarning( "fgDeinitialize(): " "no valid initialization has been performed" ); return; } /* fgState.Initialised = GL_FALSE; */ /* * If there was a menu created, destroy the rendering context */ if( fgStructure.MenuContext ) { free( fgStructure.MenuContext ); fgStructure.MenuContext = NULL; } fgDestroyStructure( ); while( (timer = fgState.Timers.First) ) { fgListRemove( &fgState.Timers, &timer->Node ); free( timer ); } while( (timer = fgState.FreeTimers.First) ) { fgListRemove( &fgState.FreeTimers, &timer->Node ); free( timer ); } #ifndef _WIN32_WCE fgJoystickClose( ); #endif fgState.Initialised = GL_FALSE; fgState.Position.X = -1; fgState.Position.Y = -1; fgState.Position.Use = GL_FALSE; fgState.Size.X = 240; fgState.Size.Y = 320; fgState.Size.Use = GL_TRUE; fgState.DisplayMode = GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH; fgState.ForceDirectContext = GL_FALSE; fgState.TryDirectContext = GL_TRUE; fgState.ForceIconic = GL_FALSE; fgState.UseCurrentContext = GL_FALSE; fgState.GLDebugSwitch = GL_FALSE; fgState.XSyncSwitch = GL_FALSE; fgState.ActionOnWindowClose = GLUT_ACTION_EXIT; fgState.ExecState = GLUT_EXEC_STATE_INIT; fgState.IgnoreKeyRepeat = GL_TRUE; fgState.Modifiers = 0xffffffff; fgState.GameModeSize.X = 240; fgState.GameModeSize.Y = 320; fgState.GameModeDepth = 16; fgState.GameModeRefresh = 72; fgState.Time.Set = GL_FALSE; fgListInit( &fgState.Timers ); fgListInit( &fgState.FreeTimers ); fgState.IdleCallback = NULL; fgState.MenuStateCallback = ( FGCBMenuState )NULL; fgState.MenuStatusCallback = ( FGCBMenuStatus )NULL; fgState.SwapCount = 0; fgState.SwapTime = 0; fgState.FPSInterval = 0; if( fgState.ProgramName ) { free( fgState.ProgramName ); fgState.ProgramName = NULL; } __glDestroy(); #if TARGET_HOST_UNIX_X11 /* * Make sure all X-client data we have created will be destroyed on * display closing */ XSetCloseDownMode( fgDisplay.Display, DestroyAll ); /* * Close the display connection, destroying all windows we have * created so far */ XCloseDisplay( fgDisplay.Display ); #endif }
/* * Perform the freeglut deinitialization... */ void fgDeinitialize( void ) { SFG_Timer *timer; if( !fgState.Initialised ) { return; } /* If we're in game mode, we want to leave game mode */ if( fgStructure.GameModeWindow ) { glutLeaveGameMode(); } /* If there was a menu created, destroy the rendering context */ if( fgStructure.MenuContext ) { #if TARGET_HOST_POSIX_X11 /* Note that the MVisualInfo is not owned by the MenuContext! */ glXDestroyContext( fgDisplay.Display, fgStructure.MenuContext->MContext ); #endif free( fgStructure.MenuContext ); fgStructure.MenuContext = NULL; } fgDestroyStructure( ); while( ( timer = fgState.Timers.First) ) { fgListRemove( &fgState.Timers, &timer->Node ); free( timer ); } while( ( timer = fgState.FreeTimers.First) ) { fgListRemove( &fgState.FreeTimers, &timer->Node ); free( timer ); } #if !defined(_WIN32_WCE) if ( fgState.JoysticksInitialised ) fgJoystickClose( ); if ( fgState.InputDevsInitialised ) fgInputDeviceClose( ); #endif /* !defined(_WIN32_WCE) */ fgState.JoysticksInitialised = GL_FALSE; fgState.InputDevsInitialised = GL_FALSE; fgState.MouseWheelTicks = 0; fgState.MajorVersion = 1; fgState.MinorVersion = 0; fgState.ContextFlags = 0; fgState.ContextProfile = 0; fgState.Initialised = GL_FALSE; fgState.Position.X = -1; fgState.Position.Y = -1; fgState.Position.Use = GL_FALSE; fgState.Size.X = 300; fgState.Size.Y = 300; fgState.Size.Use = GL_TRUE; fgState.DisplayMode = GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH; fgState.DirectContext = GLUT_TRY_DIRECT_CONTEXT; fgState.ForceIconic = GL_FALSE; fgState.UseCurrentContext = GL_FALSE; fgState.GLDebugSwitch = GL_FALSE; fgState.XSyncSwitch = GL_FALSE; fgState.ActionOnWindowClose = GLUT_ACTION_EXIT; fgState.ExecState = GLUT_EXEC_STATE_INIT; fgState.KeyRepeat = GLUT_KEY_REPEAT_ON; fgState.Modifiers = INVALID_MODIFIERS; fgState.GameModeSize.X = -1; fgState.GameModeSize.Y = -1; fgState.GameModeDepth = -1; fgState.GameModeRefresh = -1; fgListInit( &fgState.Timers ); fgListInit( &fgState.FreeTimers ); fgState.IdleCallback = NULL; fgState.MenuStateCallback = ( FGCBMenuState )NULL; fgState.MenuStatusCallback = ( FGCBMenuStatus )NULL; fgState.SwapCount = 0; fgState.SwapTime = 0; fgState.FPSInterval = 0; if( fgState.ProgramName ) { free( fgState.ProgramName ); fgState.ProgramName = NULL; } #if TARGET_HOST_POSIX_X11 /* * Make sure all X-client data we have created will be destroyed on * display closing */ XSetCloseDownMode( fgDisplay.Display, DestroyAll ); /* * Close the display connection, destroying all windows we have * created so far */ XCloseDisplay( fgDisplay.Display ); #elif TARGET_HOST_MS_WINDOWS if( fgDisplay.DisplayName ) { free( fgDisplay.DisplayName ); fgDisplay.DisplayName = NULL; } /* Reset the timer granularity */ timeEndPeriod ( 1 ); #endif fgState.Initialised = GL_FALSE; }