Here is another test app. It works the same as the above, but it uses a different method to attempt to change between modes.
The first app creates a canvas graphics context, and each time it switches to fullscreen it creates a new fullscreen graphics context.
This app creates a new fullscreen context each time you switch to fullscreen just like the other app, but it also creates a whole new canvas each time you switch to windowed mode, freeing the old one on switch to windowed mode.
This one displays the start menu bar flicker right away in OpenGL, and in DirectX fails to switch back to fullscreen from the canvas.
The first app creates a canvas graphics context, and each time it switches to fullscreen it creates a new fullscreen graphics context.
This app creates a new fullscreen context each time you switch to fullscreen just like the other app, but it also creates a whole new canvas each time you switch to windowed mode, freeing the old one on switch to windowed mode.
This one displays the start menu bar flicker right away in OpenGL, and in DirectX fails to switch back to fullscreen from the canvas.
'SetGraphicsDriver GLMax2DDriver() Global App:Application = Application.Create("Fruit Sliders", 800, 600, 0, True) Image:TImage = CreateImage(32, 32) DrawImage(Image, 0, 0) Repeat If KeyHit(KEY_F) App.ToggleFullscreen() DebugLog("State : " + App.Windowed) EndIf Flip True Until KeyHit(KEY_ESCAPE) Type Application Field Name$ Field Width% Field Height% Field Depth% Field Window:TGadget Field Canvas:TGadget Field Panel:TGadget Field TG_FullScreen:TGraphics Field TG_Canvas:TGraphics Field Windowed% ' ------------------------------------------------------------------------------------------------------------------------------------------------------- ' This function creates the game window, and sets up the graphics objects for windowed and fullscreen modes. ' ------------------------------------------------------------------------------------------------------------------------------------------------------- Function Create:Application(AppName$, AppWidth%, AppHeight%, AppDepth%=0, Fullscreen%=False) Local X%, Y% Local App:Application 'SetGraphicsDriver GLMax2DDriver() ' Create new application. App = New Application ' Store application settings. App.Name$ = AppName$ App.Width = AppWidth App.Height = AppHeight App.Depth = AppDepth ' If Depth is 0, try to find a suitable fullscreen bit depth. If App.Depth = 0 App.Depth = 16 If GraphicsModeExists(App.Width, App.Height, 24) Then App.Depth = 24 If GraphicsModeExists(App.Width, App.Height, 32) Then App.Depth = 32 EndIf ' Create a window in the center of the screen. X = GadgetWidth(Desktop())/2 - App.Width/2 Y = GadgetHeight(Desktop())/2 - App.Height/2 App.Window = CreateWindow(App.Name$, X, Y, App.Width, App.Height, Null, WINDOW_TITLEBAR|WINDOW_RESIZABLE|WINDOW_CLIENTCOORDS|WINDOW_HIDDEN) SetMinWindowSize(App.Window, GadgetWidth(App.Window), GadgetHeight(App.Window)) ' Create a panel in the window, drawn behind the canvas, which fills the empty space around the gameplay area when the window is maximized. App.Panel = CreatePanel(0, 0, App.Width, App.Height, App.Window) SetPanelColor(App.Panel, 0, 0, 0) SetGadgetLayout(App.Panel, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED) ' Create a canvas. ' App.Canvas = CreateCanvas(ClientWidth(App.Window)/2-App.Width/2, ClientHeight(App.Window)/2-App.Height/2, App.Width, App.Height, App.Panel) ' App.TG_Canvas = CanvasGraphics(App.Canvas) ' Set game to windowed or fullscreen as desired. Select Fullscreen Case False App.SetWindowed() Case True App.SetFullscreen() End Select ' Return new application instance. Return App End Function ' ------------------------------------------------------------------------------------------------------------------------------------------------------- ' This method toggles between fullscreen or windowed mode, choosing the opposite of whichever is currently enabled. ' ------------------------------------------------------------------------------------------------------------------------------------------------------- Method ToggleFullscreen() Select Windowed Case False SetWindowed() Case True SetFullscreen() End Select End Method ' ------------------------------------------------------------------------------------------------------------------------------------------------------- ' This method puts the application in windowed mode. ' ------------------------------------------------------------------------------------------------------------------------------------------------------- Method SetWindowed() ' End fullscreen mode if enabled. If TG_Fullscreen <> Null CloseGraphics TG_Fullscreen TG_Fullscreen = Null EndIf ' Create a canvas. If Canvas = Null Canvas = CreateCanvas(ClientWidth(Window)/2-Width/2, ClientHeight(Window)/2-Height/2, Width, Height, Panel) TG_Canvas = CanvasGraphics(Canvas) EndIf If Canvas = Null Then RuntimeError("Error in Application.SetWindowed() : Could not create canvas!") If TG_Canvas = Null Then RuntimeError("Error in Application.SetWindowed() : Could not get canvas graphics context!") SetGraphics TG_Canvas Windowed = True ShowGadget Window ActivateGadget Canvas ' Canvas must be activated for input or else game will make user click on canvas before any polled keyboard input is returned. EnablePolledInput() End Method ' ------------------------------------------------------------------------------------------------------------------------------------------------------- ' This method sets the application to fullscreen mode, unless no fullscreen mode in the desired resolution exists. ' ------------------------------------------------------------------------------------------------------------------------------------------------------- Method SetFullscreen() Local G:TGraphics ' Hide window, free canvas. HideGadget Window If Canvas <> Null CloseGraphics(TG_Canvas) TG_Canvas = Null FreeGadget Canvas Canvas = Null EndIf ' Set drawing operations to fullscreen. If TG_Fullscreen = Null Then TG_Fullscreen = Graphics(Width, Height, Depth) Windowed = False ' If the operation fails, put us back in windowed mode. Otherwise, hide the window, and record that fullscreen is enabled. If TG_Fullscreen = Null RuntimeError("Error in Application.SetFullscreen() : Could not set full screen mode!") 'SetWindowed() EndIf End Method End Type ' ----------------------------------------------------------------------------------------------------------------------------------------------------------- ' This function overrides the standard RuntimeError function which does not work properly. Assert also does not work. ' ----------------------------------------------------------------------------------------------------------------------------------------------------------- Function RuntimeError(Error$) EndGraphics Notify(Error$, True) End End Function