From 18e942d4860eef076aa6fc4d590387a27ff010d2 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Tue, 26 Jun 2018 13:32:33 +0200 Subject: [PATCH] Support fullscreen with SDL2 --- src/init.c | 31 ++++++++++++++++++++++++------- src/sdlscreen.c | 15 ++++++++++++--- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/init.c b/src/init.c index d165628a..8ebfc2c4 100644 --- a/src/init.c +++ b/src/init.c @@ -1924,6 +1924,9 @@ static void Set_video_mode(short width, word fullscreen) { byte supported = 0; +#if defined(USE_SDL2) + SDL_DisplayMode dm; +#endif if (Nb_video_modes >= MAX_VIDEO_MODES-1) { @@ -1935,12 +1938,15 @@ static void Set_video_mode(short width, #if defined(USE_SDL) else if (SDL_VideoModeOK(width, height, 8, SDL_FULLSCREEN)) supported = 1; // supported -#endif - else - { - // Non supporte : on ne le prend pas - return; +#elif defined(USE_SDL2) + else if (SDL_GetDisplayMode(0, mode, &dm) == 0) { + if (width == dm.w && height == dm.h) + supported = 1; } +#endif + + if (!supported) // Not supported : skip this mode + return; Video_mode[Nb_video_modes].Width = width; Video_mode[Nb_video_modes].Height = height; @@ -2082,10 +2088,21 @@ void Set_all_video_modes(void) #elif defined(USE_SDL2) { SDL_DisplayMode dm; - if (SDL_GetDesktopDisplayMode(0, &dm) == 0) + int num_modes, mode; + int display = 0; + + + num_modes = SDL_GetNumDisplayModes(display); + for (mode = num_modes; mode >= 0; mode--) // reverse order. from small resolution to big resolution + { + if (SDL_GetDisplayMode(display, mode, &dm) == 0) + Set_video_mode(dm.w, dm.h, mode, 1); + } + + if (SDL_GetDesktopDisplayMode(display, &dm) == 0) { // Set the native desktop video mode - Set_video_mode(dm.w, dm.h, 0, 1); + Set_video_mode(dm.w, dm.h, num_modes + 1, 1); } } #elif defined(WIN32) diff --git a/src/sdlscreen.c b/src/sdlscreen.c index 8562c743..f13e506a 100644 --- a/src/sdlscreen.c +++ b/src/sdlscreen.c @@ -151,8 +151,11 @@ void GFX2_Set_mode(int *width, int *height, int fullscreen) SDL_SetWindowIcon(Window_SDL, icon); Renderer_SDL = SDL_CreateRenderer(Window_SDL, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); } - //else - // SDL_SetWindowSize(Window_SDL, *width, *height); + else + { + SDL_SetWindowSize(Window_SDL, *width, *height); + SDL_SetWindowFullscreen(Window_SDL, fullscreen?SDL_WINDOW_FULLSCREEN:0); + } //SDL_GetWindowSize(Window_SDL, width, height); if (Texture_SDL != NULL) SDL_DestroyTexture(Texture_SDL); @@ -199,7 +202,13 @@ static void GFX2_UpdateRect(int x, int y, int width, int height) source_rect.h = height; } - if (RGBcopy == NULL) + if (RGBcopy != NULL && (Screen_SDL->w > RGBcopy->w || Screen_SDL->h > RGBcopy->h)) + { + SDL_FreeSurface(RGBcopy); + RGBcopy = NULL; + } + + if (RGBcopy == NULL) { RGBcopy = SDL_CreateRGBSurface(0, Screen_SDL->w, Screen_SDL->h,