diff --git a/source/director.cpp b/source/director.cpp index efdc1a1..73910cd 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -20,6 +20,7 @@ #include "lang.h" // for Lang, MAX_LANGUAGES, ba_BA, en_UK #include "logo.h" // for Logo #include "screen.h" // for FILTER_NEAREST, Screen, FILTER_... +#include "texture.h" // for Texture #include "title.h" // for Title #include "utils.h" // for options_t, input_t, boolToString @@ -68,6 +69,9 @@ Director::Director(int argc, const char *argv[]) // Inicializa JailAudio initJailAudio(); + // Establece el modo de escalado de texturas + Texture::setGlobalScaleMode(options->filter == FILTER_NEAREST ? SDL_SCALEMODE_NEAREST : SDL_SCALEMODE_LINEAR); + // Crea los objetos lang = new Lang(asset); lang->setLang(options->language); diff --git a/source/director.h b/source/director.h index 5ebf7fe..ac16b63 100644 --- a/source/director.h +++ b/source/director.h @@ -14,7 +14,7 @@ struct options_t; struct section_t; // Textos -constexpr const char* WINDOW_CAPTION = "Coffee Crisis"; +constexpr const char* WINDOW_CAPTION = "© 2020 Coffee Crisis — JailDesigner"; class Director { diff --git a/source/fade.cpp b/source/fade.cpp index afd8cb2..ebab3a2 100644 --- a/source/fade.cpp +++ b/source/fade.cpp @@ -10,6 +10,10 @@ Fade::Fade(SDL_Renderer *renderer) mRenderer = renderer; mBackbuffer = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); + if (mBackbuffer != nullptr) + { + SDL_SetTextureScaleMode(mBackbuffer, SDL_SCALEMODE_NEAREST); + } if (mBackbuffer == nullptr) { std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl; diff --git a/source/instructions.cpp b/source/instructions.cpp index 3f46a42..afaf8b1 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -53,7 +53,11 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, // Crea un backbuffer para el renderizador backbuffer = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT); - if (backbuffer == nullptr) + if (backbuffer != nullptr) + { + SDL_SetTextureScaleMode(backbuffer, Texture::currentScaleMode); + } + else { std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl; } diff --git a/source/screen.cpp b/source/screen.cpp index b4edc9b..0fcd139 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -29,6 +29,10 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options // Crea la textura donde se dibujan los graficos del juego gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight); + if (gameCanvas != nullptr) + { + SDL_SetTextureScaleMode(gameCanvas, options->filter == FILTER_NEAREST ? SDL_SCALEMODE_NEAREST : SDL_SCALEMODE_LINEAR); + } if (gameCanvas == nullptr) { if (options->console) diff --git a/source/texture.cpp b/source/texture.cpp index 7fe008d..27be8c3 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -6,6 +6,13 @@ #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" // for stbi_failure_reason, stbi_image_free +SDL_ScaleMode Texture::currentScaleMode = SDL_SCALEMODE_NEAREST; + +void Texture::setGlobalScaleMode(SDL_ScaleMode mode) +{ + currentScaleMode = mode; +} + // Constructor Texture::Texture(SDL_Renderer *renderer, std::string path, bool verbose) { @@ -96,6 +103,9 @@ bool Texture::loadFromFile(std::string path, SDL_Renderer *renderer, bool verbos // Obtiene las dimensiones de la imagen this->width = loadedSurface->w; this->height = loadedSurface->h; + + // Aplica el modo de escalado + SDL_SetTextureScaleMode(newTexture, currentScaleMode); } // Elimina la textura cargada @@ -121,6 +131,7 @@ bool Texture::createBlank(SDL_Renderer *renderer, int width, int height, SDL_Tex { this->width = width; this->height = height; + SDL_SetTextureScaleMode(texture, currentScaleMode); } return texture != nullptr; diff --git a/source/texture.h b/source/texture.h index a1b826e..85f3d93 100644 --- a/source/texture.h +++ b/source/texture.h @@ -16,6 +16,11 @@ private: std::string path; // Ruta de la imagen de la textura public: + static SDL_ScaleMode currentScaleMode; // Modo de escalado global para nuevas texturas + + // Establece el modo de escalado global para nuevas texturas + static void setGlobalScaleMode(SDL_ScaleMode mode); + // Constructor Texture(SDL_Renderer *renderer, std::string path = "", bool verbose = false); diff --git a/source/title.cpp b/source/title.cpp index e07c6a6..8ff73e6 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -473,6 +473,8 @@ void Title::update() options->filter = FILTER_NEAREST; else options->filter = FILTER_LINEAL; + Texture::setGlobalScaleMode(options->filter == FILTER_NEAREST ? SDL_SCALEMODE_NEAREST : SDL_SCALEMODE_LINEAR); + reLoadTextures(); updateMenuLabels(); break; @@ -1058,6 +1060,10 @@ void Title::createTiledBackground() { // Crea la textura para el mosaico de fondo background = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH * 2, GAMECANVAS_HEIGHT * 2); + if (background != nullptr) + { + SDL_SetTextureScaleMode(background, Texture::currentScaleMode); + } if (background == nullptr) { if (options->console) diff --git a/source/title.h b/source/title.h index 0453685..92e9221 100644 --- a/source/title.h +++ b/source/title.h @@ -20,7 +20,7 @@ struct JA_Music_t; struct JA_Sound_t; // Textos -constexpr const char *TEXT_COPYRIGHT = "@2020,2023 JailDesigner (v2.3.2)"; +constexpr const char *TEXT_COPYRIGHT = "@2020 JailDesigner (v2.3.3)"; // Contadores constexpr int TITLE_COUNTER = 800;