From 22b62dd46b7ae4adaa4596eee68a2416e20ebe0f Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Tue, 18 Nov 2025 10:08:35 +0100 Subject: [PATCH] =?UTF-8?q?-=20[FIX]=20Render=20final=20a=20textura,=20per?= =?UTF-8?q?=20a=20evitar=20la=20merda=20que=20clava=20la=20GPU=20si=20s'us?= =?UTF-8?q?a=20acceleraci=C3=B3=20hardware?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- source/japi/draw.cpp | 14 +++++++++++++- source/japi/draw.h | 1 + source/japi/game.cpp | 4 ++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index a20dd7d..756ff6c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .vscode/* dilemmaker -build/* \ No newline at end of file +build/* +*.exe diff --git a/source/japi/draw.cpp b/source/japi/draw.cpp index 6555394..fbf2da9 100644 --- a/source/japi/draw.cpp +++ b/source/japi/draw.cpp @@ -7,6 +7,7 @@ namespace draw { SDL_Window *sdl_window {nullptr}; // La finestra de SDL SDL_Renderer *sdl_renderer {nullptr}; // El renderer de SDL + SDL_Texture *sdl_texture {nullptr}; // La textura a la que ho renderitze tot SDL_Texture *sdl_source {nullptr}; void init(const char *titol, const uint16_t width, const uint16_t height) @@ -22,9 +23,17 @@ namespace draw SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "ERROR (draw::init): Failed to initialize renderer!\n"); exit(1); } + + sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, width, height); //SDL_SetRenderDrawBlendMode(sdl_renderer, SDL_BLENDMODE_BLEND); } + void resizeSystemTexture(const uint16_t width, const uint16_t height) + { + SDL_DestroyTexture(sdl_texture); + sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, width, height); + } + void quit() { SDL_DestroyRenderer(sdl_renderer); @@ -82,7 +91,7 @@ namespace draw void setDestination(SDL_Texture *surf) { - SDL_SetRenderTarget(sdl_renderer, surf); + SDL_SetRenderTarget(sdl_renderer, surf ? surf : sdl_texture); } void setSource(SDL_Texture *surf) @@ -185,7 +194,10 @@ namespace draw // Refresca la pantalla void render() { + SDL_SetRenderTarget(sdl_renderer, nullptr); + SDL_RenderTexture(sdl_renderer, sdl_texture, nullptr, nullptr); SDL_RenderPresent(sdl_renderer); + SDL_SetRenderTarget(sdl_renderer, sdl_texture); } } diff --git a/source/japi/draw.h b/source/japi/draw.h index 5f8bdde..34389c0 100644 --- a/source/japi/draw.h +++ b/source/japi/draw.h @@ -7,6 +7,7 @@ namespace draw enum flip { none, horizontal, vertical, both }; void init(const char *titol, const uint16_t width, const uint16_t height); + void resizeSystemTexture(const uint16_t width, const uint16_t height); void quit(); SDL_Texture *createSurface(const uint16_t w, const uint16_t h); diff --git a/source/japi/game.cpp b/source/japi/game.cpp index 1c2613b..8c2cf7f 100644 --- a/source/japi/game.cpp +++ b/source/japi/game.cpp @@ -114,6 +114,10 @@ int main(int argc, char *argv[]) { game::windowHasFocus = false; } + if (e.type == SDL_EVENT_WINDOW_RESIZED) + { + draw::resizeSystemTexture(e.window.data1, e.window.data2); + } } if (SDL_GetTicks()-current_ticks >= game::ticks_per_frame)