From 554d6dcc84e3fb009c9c41dfff5d5f8b9352fc77 Mon Sep 17 00:00:00 2001 From: 14162326141 Date: Fri, 31 Dec 2021 19:03:10 -0500 Subject: [PATCH] Stop using SDL_GetWindowSurface --- src/core_lua.c | 14 +++++++++----- src/display_sdl.c | 3 +-- src/display_sdl.h | 1 - src/main.c | 9 ++------- src/wait.c | 19 +++++++++++-------- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/core_lua.c b/src/core_lua.c index 1f62369308..22b0be8792 100644 --- a/src/core_lua.c +++ b/src/core_lua.c @@ -674,12 +674,14 @@ extern bool is_fullscreen; extern bool is_borderless; static int sdl_screen_size(lua_State *L) { - lua_pushnumber(L, screen->w / screen_zoom); - lua_pushnumber(L, screen->h / screen_zoom); + int window_w, window_h; + SDL_GetWindowSize(window, &window_w, &window_h); + lua_pushnumber(L, window_w / screen_zoom); + lua_pushnumber(L, window_h / screen_zoom); lua_pushboolean(L, is_fullscreen); lua_pushboolean(L, is_borderless); - lua_pushnumber(L, screen->w); - lua_pushnumber(L, screen->h); + lua_pushnumber(L, window_w); + lua_pushnumber(L, window_h); return 6; } @@ -2362,7 +2364,9 @@ static int gl_scissor(lua_State *L) float y = luaL_checknumber(L, 3); float w = luaL_checknumber(L, 4); float h = luaL_checknumber(L, 5); - y = screen->h / screen_zoom - y - h; + int window_h; + SDL_GetWindowSize(window, NULL, &window_h); + y = window_h / screen_zoom - y - h; glScissor(x, y, w, h); } else glDisable(GL_SCISSOR_TEST); return 0; diff --git a/src/display_sdl.c b/src/display_sdl.c index 61b2f0e955..df27eeae6b 100644 --- a/src/display_sdl.c +++ b/src/display_sdl.c @@ -22,7 +22,6 @@ #include #define DISPLAY_CHAR_SIZE 16 -SDL_Surface *screen = NULL; void display_put_char(SDL_Surface *surface, char c, int x, int y, int r, int g, int b) { @@ -39,7 +38,7 @@ void display_put_char(SDL_Surface *surface, char c, int x, int y, int r, int g, rect.w = rect.h = DISPLAY_CHAR_SIZE - 1; } - SDL_FillRect(surface, &rect, SDL_MapRGB(screen->format, r, g, b)); + SDL_FillRect(surface, &rect, SDL_MapRGB(surface->format, r, g, b)); } void display_put_string(SDL_Surface *surface, const char *s, int x, int y, int r, int g, int b) { diff --git a/src/display_sdl.h b/src/display_sdl.h index 2220ad2477..05351a07a6 100644 --- a/src/display_sdl.h +++ b/src/display_sdl.h @@ -37,7 +37,6 @@ extern "C" { if (SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface);\ } while (0) -extern SDL_Surface *screen; void display_put_char(SDL_Surface *surface, char c, int x, int y, int r, int g, int b); void display_put_string(SDL_Surface *surface, const char *s, int x, int y, int r, int g, int b); #ifndef __APPLE__ diff --git a/src/main.c b/src/main.c index 0f353f33f5..9fc5925819 100644 --- a/src/main.c +++ b/src/main.c @@ -1088,7 +1088,6 @@ void do_resize(int w, int h, bool fullscreen, bool borderless, float zoom) SDL_DestroyWindow(window); maincontext = 0; window = 0; - screen = 0; /* Clean up the old window icon */ SDL_FreeSurface(windowIconSurface); windowIconSurface = 0; @@ -1112,7 +1111,6 @@ void do_resize(int w, int h, bool fullscreen, bool borderless, float zoom) } is_fullscreen = fullscreen; is_borderless = borderless; - screen = SDL_GetWindowSurface(window); maincontext = SDL_GL_CreateContext(window); SDL_GL_MakeCurrent(window, maincontext); glewInit(); @@ -1177,9 +1175,6 @@ void do_resize(int w, int h, bool fullscreen, bool borderless, float zoom) } - /* Finally, update the screen info */ - screen = SDL_GetWindowSurface(window); - } /* Check and see if SDL honored our resize request */ @@ -1543,8 +1538,8 @@ int main(int argc, char *argv[]) boot_lua(1, FALSE, argc, argv); do_resize(WIDTH, HEIGHT, FALSE, FALSE, screen_zoom); - if (screen==NULL) { - printf("error opening screen: %s\n", SDL_GetError()); + if (window==NULL) { + printf("error opening window: %s\n", SDL_GetError()); return 3; } diff --git a/src/wait.c b/src/wait.c index 6db8e8ae6f..6e9bc6acac 100644 --- a/src/wait.c +++ b/src/wait.c @@ -30,7 +30,6 @@ #include "lua_externs.h" extern SDL_Window *window; -extern SDL_Surface *screen; static int wait_hooked = 0; static bool manual_ticks_enabled = FALSE; @@ -46,13 +45,15 @@ static int draw_last_frame(lua_State *L) { if (!bkg_t) return 0; - float w = screen->w / screen_zoom; - float h = screen->h / screen_zoom; + int window_w, window_h; + SDL_GetWindowSize(window, &window_w, &window_h); + float w = window_w / screen_zoom; + float h = window_h / screen_zoom; GLfloat btexcoords[2*4] = { - 0, (float)screen->h/(float)bkg_realh, - (float)screen->w/(float)bkg_realw, (float)screen->h/(float)bkg_realh, - (float)screen->w/(float)bkg_realw, 0, + 0, (float)window_h/(float)bkg_realh, + (float)window_w/(float)bkg_realw, (float)window_h/(float)bkg_realh, + (float)window_w/(float)bkg_realw, 0, 0, 0 }; GLfloat bcolors[4*4] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; @@ -119,8 +120,10 @@ static int enable(lua_State *L) SDL_GL_SwapWindow(window); - float w = screen->w; - float h = screen->h; + int window_w, window_h; + SDL_GetWindowSize(window, &window_w, &window_h); + float w = window_w; + float h = window_h; bkg_w = w; bkg_h = h; -- 2.34.1