Support fullscreen with SDL2
This commit is contained in:
parent
099301721e
commit
18e942d486
31
src/init.c
31
src/init.c
@ -1924,6 +1924,9 @@ static void Set_video_mode(short width,
|
|||||||
word fullscreen)
|
word fullscreen)
|
||||||
{
|
{
|
||||||
byte supported = 0;
|
byte supported = 0;
|
||||||
|
#if defined(USE_SDL2)
|
||||||
|
SDL_DisplayMode dm;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (Nb_video_modes >= MAX_VIDEO_MODES-1)
|
if (Nb_video_modes >= MAX_VIDEO_MODES-1)
|
||||||
{
|
{
|
||||||
@ -1935,12 +1938,15 @@ static void Set_video_mode(short width,
|
|||||||
#if defined(USE_SDL)
|
#if defined(USE_SDL)
|
||||||
else if (SDL_VideoModeOK(width, height, 8, SDL_FULLSCREEN))
|
else if (SDL_VideoModeOK(width, height, 8, SDL_FULLSCREEN))
|
||||||
supported = 1; // supported
|
supported = 1; // supported
|
||||||
#endif
|
#elif defined(USE_SDL2)
|
||||||
else
|
else if (SDL_GetDisplayMode(0, mode, &dm) == 0) {
|
||||||
{
|
if (width == dm.w && height == dm.h)
|
||||||
// Non supporte : on ne le prend pas
|
supported = 1;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!supported) // Not supported : skip this mode
|
||||||
|
return;
|
||||||
|
|
||||||
Video_mode[Nb_video_modes].Width = width;
|
Video_mode[Nb_video_modes].Width = width;
|
||||||
Video_mode[Nb_video_modes].Height = height;
|
Video_mode[Nb_video_modes].Height = height;
|
||||||
@ -2082,10 +2088,21 @@ void Set_all_video_modes(void)
|
|||||||
#elif defined(USE_SDL2)
|
#elif defined(USE_SDL2)
|
||||||
{
|
{
|
||||||
SDL_DisplayMode dm;
|
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 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)
|
#elif defined(WIN32)
|
||||||
|
|||||||
@ -151,8 +151,11 @@ void GFX2_Set_mode(int *width, int *height, int fullscreen)
|
|||||||
SDL_SetWindowIcon(Window_SDL, icon);
|
SDL_SetWindowIcon(Window_SDL, icon);
|
||||||
Renderer_SDL = SDL_CreateRenderer(Window_SDL, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
Renderer_SDL = SDL_CreateRenderer(Window_SDL, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||||
}
|
}
|
||||||
//else
|
else
|
||||||
// SDL_SetWindowSize(Window_SDL, *width, *height);
|
{
|
||||||
|
SDL_SetWindowSize(Window_SDL, *width, *height);
|
||||||
|
SDL_SetWindowFullscreen(Window_SDL, fullscreen?SDL_WINDOW_FULLSCREEN:0);
|
||||||
|
}
|
||||||
//SDL_GetWindowSize(Window_SDL, width, height);
|
//SDL_GetWindowSize(Window_SDL, width, height);
|
||||||
if (Texture_SDL != NULL)
|
if (Texture_SDL != NULL)
|
||||||
SDL_DestroyTexture(Texture_SDL);
|
SDL_DestroyTexture(Texture_SDL);
|
||||||
@ -199,6 +202,12 @@ static void GFX2_UpdateRect(int x, int y, int width, int height)
|
|||||||
source_rect.h = height;
|
source_rect.h = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (RGBcopy != NULL && (Screen_SDL->w > RGBcopy->w || Screen_SDL->h > RGBcopy->h))
|
||||||
|
{
|
||||||
|
SDL_FreeSurface(RGBcopy);
|
||||||
|
RGBcopy = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (RGBcopy == NULL)
|
if (RGBcopy == NULL)
|
||||||
{
|
{
|
||||||
RGBcopy = SDL_CreateRGBSurface(0,
|
RGBcopy = SDL_CreateRGBSurface(0,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user