From: DeaDDooMER Date: Wed, 1 Apr 2020 07:45:56 +0000 (+0400) Subject: sdl: fix fullscreen X-Git-Url: http://deadsoftware.ru/gitweb?p=flatwaifu.git;a=commitdiff_plain;h=9b7dd9e2d0728c50f830fff8f5f7c7caa87e5b6f sdl: fix fullscreen --- diff --git a/src/gl/render.c b/src/gl/render.c index 73ce92a..b2c625f 100644 --- a/src/gl/render.c +++ b/src/gl/render.c @@ -1670,6 +1670,8 @@ void R_alloc (void) { } } +static void R_reload_textures (void); + void R_set_videomode (int w, int h, int fullscreen) { assert(w > 0); assert(h > 0); @@ -1678,29 +1680,39 @@ void R_set_videomode (int w, int h, int fullscreen) { if (fullscreen) { flags |= SYSTEM_USE_FULLSCREEN; } + if (root != NULL) { + R_cache_free(root, 0); + root = NULL; + } int res = Y_set_videomode(w, h, flags); if (res == 0) { if (was == 0) { ERR_failinit("Unable to set video mode\n"); } } else { - SCRW = w; - SCRH = h; + Y_get_videomode(&SCRW, &SCRH); + root = R_cache_new(); + assert(root); + R_alloc(); + R_reload_textures(); } } void R_toggle_fullscreen (void) { + R_cache_free(root, 0); Y_set_fullscreen(!Y_get_fullscreen()); fullscreen = Y_get_fullscreen(); + Y_get_videomode(&SCRW, &SCRH); + root = R_cache_new(); + assert(root); + R_alloc(); + R_reload_textures(); } void R_init (void) { logo("R_init: intialize opengl render\n"); R_init_playpal(); R_set_videomode(SCRW, SCRH, fullscreen); - root = R_cache_new(); - assert(root); - R_alloc(); } void R_done (void) { @@ -1744,6 +1756,18 @@ int R_get_special_id (int n) { return walp[n].res == -2 ? (intptr_t)walp[n].n : -1; } +static void R_reload_textures (void) { + int i; + char s[8]; + for (i = 0; i < max_textures; i++) { + R_get_name(i, s); + if (walp[i].res >= 0) { + walp[i] = R_gl_getimage(walp[i].res); + } + } + horiz = R_gl_getimage(horiz.res); +} + void R_begin_load (void) { int i; for (i = 0; i < 256; i++) { @@ -1812,6 +1836,7 @@ void R_end_load (void) { if (k >= 256) { k = j; j += 1; + max_textures += 1; walp[k] = R_gl_getimage(g); walf[k] = g & 0x8000 ? 1 : 0; } diff --git a/src/sdl/main.c b/src/sdl/main.c index 5706cc7..07dccf9 100644 --- a/src/sdl/main.c +++ b/src/sdl/main.c @@ -115,6 +115,16 @@ int Y_set_videomode (int w, int h, int flags) { return s != NULL; } +void Y_get_videomode (int *w, int *h) { + if (surf != NULL) { + *w = surf->w; + *h = surf->h; + } else { + *w = 0; + *h = 0; + } +} + int Y_videomode_setted (void) { return surf != NULL; } @@ -125,9 +135,13 @@ void Y_unset_videomode (void) { SDL_InitSubSystem(SDL_INIT_VIDEO); } -int Y_set_fullscreen (int yes) { - //SDL_WM_ToggleFullScreen(); - return 0; +void Y_set_fullscreen (int yes) { + assert(surf != NULL); + Uint32 flags = surf->flags & ~SDL_FULLSCREEN; + if ((surf->flags & SDL_FULLSCREEN) == 0) { + flags |= SDL_FULLSCREEN; + } + Y_set_videomode(surf->w, surf->h, flags); } int Y_get_fullscreen (void) { diff --git a/src/sdl2/main.c b/src/sdl2/main.c index dd5b8d4..c1b872c 100644 --- a/src/sdl2/main.c +++ b/src/sdl2/main.c @@ -158,6 +158,15 @@ int Y_set_videomode (int w, int h, int flags) { } } +void Y_get_videomode (int *w, int *h) { + if (window != NULL) { + SDL_GetWindowSize(window, w, h); + } else { + *w = 0; + *h = 0; + } +} + int Y_videomode_setted (void) { return window != NULL; } diff --git a/src/soft/render.c b/src/soft/render.c index aaaea63..fafe379 100644 --- a/src/soft/render.c +++ b/src/soft/render.c @@ -1360,15 +1360,18 @@ void R_set_videomode (int w, int h, int fullscreen) { ERR_failinit("Unable to set video mode"); } } else { - SCRW = w; - SCRH = h; + Y_get_videomode(&SCRW, &SCRH); Y_get_buffer(&buffer, &buf_w, &buf_h, &pitch); + R_setgamma(gammaa); } } void R_toggle_fullscreen (void) { Y_set_fullscreen(!Y_get_fullscreen()); fullscreen = Y_get_fullscreen(); + Y_get_videomode(&SCRW, &SCRH); + Y_get_buffer(&buffer, &buf_w, &buf_h, &pitch); + R_setgamma(gammaa); } void R_init () { @@ -1381,7 +1384,6 @@ void R_init () { F_loadres(F_getresid("MIXMAP"), mixmap, 0, 0x10000); F_loadres(F_getresid("COLORMAP"), clrmap, 0, 256*12); R_set_videomode(SCRW, SCRH, fullscreen); - R_setgamma(gammaa); V_setrect(0, SCRW, 0, SCRH); V_clr(0, SCRW, 0, SCRH, 0); R_alloc(); diff --git a/src/soft/vga.c b/src/soft/vga.c index d9c77e1..ce83101 100644 --- a/src/soft/vga.c +++ b/src/soft/vga.c @@ -78,9 +78,9 @@ static void draw_rect (int x, int y, int w, int h, int c) { void V_setrect (short x, short w, short y, short h) { cx1 = max(x, 0); - cx2 = min(x + w - 1, SCRW - 1); + cx2 = min(x + w - 1, buf_w - 1); cy1 = max(y, 0); - cy2 = min(y + h - 1, SCRH - 1); + cy2 = min(y + h - 1, buf_h - 1); } static void putpixel (int x, int y, byte color) { @@ -100,7 +100,7 @@ static void mappixel (int x, int y, byte *cmap) { void V_center (int f) { if (f) { - V_offset(SCRW / 2 - 320 / 2, SCRH / 2 - 200 / 2); + V_offset(buf_w / 2 - 320 / 2, buf_h / 2 - 200 / 2); } else { V_offset(0, 0); } diff --git a/src/system.h b/src/system.h index 37d2854..445de10 100644 --- a/src/system.h +++ b/src/system.h @@ -8,9 +8,10 @@ /* common video subsystem routines */ int Y_set_videomode (int w, int h, int flags); +void Y_get_videomode (int *w, int *h); int Y_videomode_setted (void); void Y_unset_videomode (void); -int Y_set_fullscreen (int yes); +void Y_set_fullscreen (int yes); int Y_get_fullscreen (void); /* hardware specific rendering */