From 404824994c4ec765bf9177fa0f4464ff7a17c929 Mon Sep 17 00:00:00 2001 From: Robin Gustafsson Date: Thu, 10 Nov 2016 23:00:52 +0100 Subject: [PATCH] Fix SDL2 rendering The pdc_render and pdc_texture globals are no longer needed. --- doc/sdl2.txt | 11 ++++------- sdl2/pdcdisp.c | 14 ++------------ sdl2/pdckbd.c | 3 +-- sdl2/pdcscrn.c | 28 ---------------------------- sdl2/pdcsdl.h | 2 -- 5 files changed, 7 insertions(+), 51 deletions(-) diff --git a/doc/sdl2.txt b/doc/sdl2.txt index 8048cb75..0770b53b 100644 --- a/doc/sdl2.txt +++ b/doc/sdl2.txt @@ -52,8 +52,6 @@ variables: The SDL2 port adds: SDL_Window *pdc_window; - SDL_Renderer *pdc_render; - SDL_Texture *pdc_texture; Using SDL_ttf (with SDL2 or SDL) adds: @@ -64,11 +62,10 @@ Using SDL_ttf (with SDL2 or SDL) adds: int pdc_ttffont_hint; These can be used or modified in your own code. Like the pdc_screen variable -used by the SDL port, you can initialize pdc_window, pdc_render, -pdc_texture in your own code. If it's not initialized, PDCurses will do -it for you. See the sdltest demo for an example. If PDCurses is built with -the PDC_WIDE flag, it will clean up/deallocate these variables on exit when -needed. +used by the SDL port, you can initialize pdc_window in your own code. If it's +not initialized, PDCurses will do it for you. See the sdltest demo for an +example. If PDCurses is built with the PDC_WIDE flag, it will clean up/ +deallocate these variables on exit when needed. Default font for SDL_TTF is assumed to be DejaVuSansMono.ttf from the Open Source DejaVu fonts. The code looks for this font to already be installed in diff --git a/sdl2/pdcdisp.c b/sdl2/pdcdisp.c index a7e642bd..c84de684 100644 --- a/sdl2/pdcdisp.c +++ b/sdl2/pdcdisp.c @@ -85,19 +85,9 @@ void PDC_update_rects(void) probably better off doing a full screen update */ if (rectcount == MAXRECT) - { - SDL_UpdateTexture(pdc_texture, NULL, pdc_screen->pixels, pdc_screen->pitch); - SDL_RenderClear(pdc_render); - SDL_RenderCopy(pdc_render, pdc_texture, NULL, NULL); - SDL_RenderPresent(pdc_render); - } + SDL_UpdateWindowSurface(pdc_window); else - { - SDL_UpdateTexture(pdc_texture, NULL, pdc_screen->pixels, pdc_screen->pitch); - SDL_RenderClear(pdc_render); - SDL_RenderCopy(pdc_render, pdc_texture, NULL, NULL); - SDL_RenderPresent(pdc_render); - } + SDL_UpdateWindowSurfaceRects(pdc_window, uprect, rectcount); pdc_lastupdate = SDL_GetTicks(); rectcount = 0; diff --git a/sdl2/pdckbd.c b/sdl2/pdckbd.c index dc104cb4..4e884469 100644 --- a/sdl2/pdckbd.c +++ b/sdl2/pdckbd.c @@ -466,8 +466,7 @@ int PDC_get_key(void) break; case SDL_WINDOWEVENT_RESTORED: case SDL_WINDOWEVENT_EXPOSED: - SDL_RenderPresent(pdc_render); -/* SDL_UpdateWindowSurface(pdc_window); */ + SDL_UpdateWindowSurface(pdc_window); break; } break; diff --git a/sdl2/pdcscrn.c b/sdl2/pdcscrn.c index ad711de6..cd98e3dc 100644 --- a/sdl2/pdcscrn.c +++ b/sdl2/pdcscrn.c @@ -9,8 +9,6 @@ RCSID("$Id: pdcscrn.c,v 1.34 2008/07/14 04:24:52 wmcbrine Exp $") #include "deficon.h" SDL_Window *pdc_window = NULL; -SDL_Renderer *pdc_render = NULL; -SDL_Texture *pdc_texture = NULL; SDL_Surface *pdc_screen = NULL, *pdc_font = NULL, *pdc_icon = NULL, *pdc_back = NULL, *pdc_tileback = NULL; int pdc_sheight = 0, pdc_swidth = 0, pdc_yoffset = 0, pdc_xoffset = 0; @@ -64,16 +62,6 @@ void PDC_clean(void) SDL_FreeSurface(pdc_font); pdc_font = NULL; } - if (pdc_texture != NULL) - { - SDL_DestroyTexture (pdc_texture); - pdc_texture = NULL; - } - if (pdc_render != NULL) - { - SDL_DestroyRenderer (pdc_render); - pdc_render = NULL; - } if (pdc_window != NULL) { SDL_DestroyWindow(pdc_window); @@ -261,18 +249,6 @@ int PDC_scr_open(int argc, char **argv) fprintf(stderr, "Could not open SDL window surface: %s\n", SDL_GetError()); return ERR; } - pdc_render = SDL_CreateRenderer(pdc_window, -1, 0); - if (pdc_render == NULL) - { - fprintf(stderr, "Could not open SDL window renderer: %s\n", SDL_GetError()); - return ERR; - } - pdc_texture = SDL_CreateTexture(pdc_render, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, pdc_swidth, pdc_sheight); - if (pdc_texture == NULL) - { - fprintf(stderr, "Could not open SDL texture: %s\n", SDL_GetError()); - return ERR; - } } else { @@ -338,10 +314,6 @@ int PDC_resize_screen(int nlines, int ncols) SDL_SetWindowSize(pdc_window, pdc_swidth, pdc_sheight); pdc_screen = SDL_GetWindowSurface(pdc_window); - if (pdc_texture != NULL) - SDL_DestroyTexture (pdc_texture); - SDL_RenderClear(pdc_render); - pdc_texture = SDL_CreateTexture(pdc_render, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, pdc_swidth, pdc_sheight); if (pdc_tileback) PDC_retile(); diff --git a/sdl2/pdcsdl.h b/sdl2/pdcsdl.h index 17587b23..79f25f76 100644 --- a/sdl2/pdcsdl.h +++ b/sdl2/pdcsdl.h @@ -8,8 +8,6 @@ #include PDCEX SDL_Window *pdc_window; -PDCEX SDL_Renderer *pdc_render; -PDCEX SDL_Texture *pdc_texture; PDCEX SDL_Surface *pdc_screen, *pdc_font, *pdc_icon, *pdc_back; PDCEX int pdc_sheight, pdc_swidth, pdc_yoffset, pdc_xoffset;