@@ -148,9 +148,26 @@ class SDLWindowViewPort: public os::Viewport {
148148 SDL_SetWindowFullscreen (_window, false );
149149 SDL_SetWindowBordered (_window, false );
150150 break ;
151- case os::ViewportState::Fullscreen:
151+ case os::ViewportState::Fullscreen: {
152+ SDL_DisplayMode target;
153+ int width, height;
154+
155+ if (SDL_GetWindowSizeInPixels (_window, &width, &height)) {
156+ if (SDL_GetClosestFullscreenDisplayMode (SDL_GetDisplayForWindow (_window),
157+ width, height, 0 .0f , true , &target))
158+ {
159+ SDL_SetWindowFullscreenMode (_window, &target);
160+ }
161+ }
162+
163+ // NOTE: This can be buggy if the mode failed to set since FSO
164+ // doesn't account for a difference between assumed window size
165+ // and actual window size. This can present as screen anomalies
166+ // such as distortion, mirroring, or flickering.
152167 SDL_SetWindowFullscreen (_window, true );
168+
153169 break ;
170+ }
154171 default :
155172 UNREACHABLE (" Invalid window state!" );
156173 break ;
@@ -229,7 +246,10 @@ std::unique_ptr<os::Viewport> SDLGraphicsOperations::createViewport(const os::Vi
229246 windowflags |= SDL_WINDOW_BORDERLESS ;
230247 }
231248 if (props.flags [os::ViewPortFlags::Fullscreen]) {
232- windowflags |= SDL_WINDOW_FULLSCREEN ;
249+ // don't set window flag here since we need to alter the display mode
250+ // first and that can only be done after the window is created
251+ //
252+ // windowflags |= SDL_WINDOW_FULLSCREEN;
233253 }
234254 if (props.flags [os::ViewPortFlags::Resizeable]) {
235255 windowflags |= SDL_WINDOW_RESIZABLE ;
@@ -273,6 +293,21 @@ std::unique_ptr<os::Viewport> SDLGraphicsOperations::createViewport(const os::Vi
273293 return nullptr ;
274294 }
275295
296+ // switch to fullscreen if we should
297+ if (props.flags [os::ViewPortFlags::Fullscreen]) {
298+ SDL_DisplayMode target;
299+
300+ if (SDL_GetClosestFullscreenDisplayMode (props.display , width, height, 0 .0f , true , &target)) {
301+ SDL_SetWindowFullscreenMode (window, &target);
302+ }
303+
304+ // NOTE: This can be buggy if the mode failed to set since FSO doesn't
305+ // account for a difference between assumed window size and actual window
306+ // size. This can present as screen anomalies such as distortion, mirroring,
307+ // or flickering.
308+ SDL_SetWindowFullscreen (window, true );
309+ }
310+
276311 SDL_SetWindowPosition (window, x, y);
277312 SDL_RaiseWindow (window);
278313
0 commit comments