SDL bug: no va el mode de pantalla completa en macos

This commit is contained in:
2025-06-22 08:02:53 +02:00
parent b438a0ae16
commit 9a6e5f775c
4 changed files with 70 additions and 62 deletions

View File

@@ -299,7 +299,7 @@ namespace shader
} }
usingOpenGL = true; usingOpenGL = true;
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Sistema de shaders inicializado correctamente."); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Shader system initialized successfully.");
return true; return true;
} }

View File

@@ -416,8 +416,6 @@ void Resource::calculateTotalResources()
{ {
auto list = Asset::get()->getListByType(asset_type); auto list = Asset::get()->getListByType(asset_type);
total += list.size(); total += list.size();
std::string log = std::to_string(list.size()) + " - " + std::to_string(total);
SDL_Log("%s", log.c_str());
} }
loading_count_ = ResourceCount(total); loading_count_ = ResourceCount(total);

View File

@@ -126,9 +126,8 @@ void Screen::renderScreen()
} }
// Establece el modo de video // Establece el modo de video
void Screen::setFullscreenMode(bool mode) void Screen::setFullscreenMode()
{ {
Options::video.fullscreen = mode;
SDL_SetWindowFullscreen(window_, Options::video.fullscreen); SDL_SetWindowFullscreen(window_, Options::video.fullscreen);
initShaders(); initShaders();
} }
@@ -270,14 +269,17 @@ void Screen::loadShaders()
// Inicializa los shaders // Inicializa los shaders
void Screen::initShaders() void Screen::initShaders()
{ {
loadShaders(); if (Options::video.shaders)
shader::init(window_, game_canvas_, shader_source_); {
loadShaders();
shader::init(window_, game_canvas_, shader_source_);
}
} }
// Calcula el tamaño de la ventana // Calcula el tamaño de la ventana
void Screen::adjustWindowSize() void Screen::adjustWindowSize()
{ {
// if (!Options::video.fullscreen) if (!Options::video.fullscreen)
{ {
// Establece el nuevo tamaño // Establece el nuevo tamaño
const int WIDTH = param.game.width * Options::window.size; const int WIDTH = param.game.width * Options::window.size;
@@ -326,55 +328,63 @@ void Screen::renderAttenuate()
// Arranca SDL VIDEO y crea la ventana // Arranca SDL VIDEO y crea la ventana
bool Screen::initSDLVideo() bool Screen::initSDLVideo()
{ {
// Indicador de éxito // Inicializar SDL
auto success = true;
// Inicializa SDL
if (!SDL_Init(SDL_INIT_VIDEO)) if (!SDL_Init(SDL_INIT_VIDEO))
{ {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_VIDEO could not initialize! SDL Error: %s", SDL_GetError()); SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
success = false; "FATAL: Failed to initialize SDL_VIDEO! SDL Error: %s",
SDL_GetError());
return false;
} }
else
// Obtener información de la pantalla
getDisplayInfo();
// Configurar hint para OpenGL
if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"))
{ {
SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "\n** SDL_VIDEO: INITIALIZING\n"); SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Warning: Failed to set OpenGL hint!");
getDisplayInfo();
if (!SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"))
{
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Warning: opengl not enabled!");
}
// Crea la ventana
window_ = SDL_CreateWindow(Options::window.caption.c_str(), param.game.width * Options::window.size, param.game.height * Options::window.size, SDL_WINDOW_OPENGL);
if (!window_)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window could not be created! SDL Error: %s", SDL_GetError());
success = false;
}
else
{
renderer_ = SDL_CreateRenderer(window_, nullptr);
if (!renderer_)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Renderer could not be created! SDL Error: %s", SDL_GetError());
success = false;
}
else
{
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
SDL_SetRenderLogicalPresentation(renderer_, param.game.width, param.game.height, Options::video.integer_scale ? SDL_LOGICAL_PRESENTATION_INTEGER_SCALE : SDL_LOGICAL_PRESENTATION_LETTERBOX);
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
SDL_SetRenderVSync(renderer_, Options::video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
SDL_SetWindowFullscreen(window_, Options::video.fullscreen);
}
}
} }
SDL_LogInfo(SDL_LOG_CATEGORY_TEST, "** SDL_VIDEO: INITIALIZATION COMPLETE\n"); // Crear ventana
return success; window_ = SDL_CreateWindow(
Options::window.caption.c_str(),
param.game.width * Options::window.size,
param.game.height * Options::window.size,
SDL_WINDOW_OPENGL);
if (!window_)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"FATAL: Failed to create window! SDL Error: %s",
SDL_GetError());
SDL_Quit();
return false;
}
// Crear renderer
renderer_ = SDL_CreateRenderer(window_, nullptr);
if (!renderer_)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"FATAL: Failed to create renderer! SDL Error: %s",
SDL_GetError());
SDL_DestroyWindow(window_);
window_ = nullptr;
SDL_Quit();
return false;
}
// Configurar renderer
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
SDL_SetRenderLogicalPresentation(renderer_, param.game.width, param.game.height, Options::video.integer_scale ? SDL_LOGICAL_PRESENTATION_INTEGER_SCALE : SDL_LOGICAL_PRESENTATION_LETTERBOX);
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
SDL_SetRenderVSync(renderer_, Options::video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
SDL_SetWindowFullscreen(window_, Options::video.fullscreen);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "SDL Video initialized successfully.");
return true;
} }
// Obtiene información sobre la pantalla // Obtiene información sobre la pantalla
@@ -458,8 +468,8 @@ void Screen::applySettings()
{ {
SDL_SetRenderVSync(renderer_, Options::video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED); SDL_SetRenderVSync(renderer_, Options::video.v_sync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
SDL_SetRenderLogicalPresentation(Screen::get()->getRenderer(), param.game.width, param.game.height, Options::video.integer_scale ? SDL_LOGICAL_PRESENTATION_INTEGER_SCALE : SDL_LOGICAL_PRESENTATION_LETTERBOX); SDL_SetRenderLogicalPresentation(Screen::get()->getRenderer(), param.game.width, param.game.height, Options::video.integer_scale ? SDL_LOGICAL_PRESENTATION_INTEGER_SCALE : SDL_LOGICAL_PRESENTATION_LETTERBOX);
setFullscreenMode();
adjustWindowSize(); adjustWindowSize();
setFullscreenMode();
} }
// Crea el objeto de texto // Crea el objeto de texto

View File

@@ -33,12 +33,12 @@ public:
void coreRender(); // Vuelca el contenido del renderizador en pantalla exceptuando ciertas partes void coreRender(); // Vuelca el contenido del renderizador en pantalla exceptuando ciertas partes
// --- Configuración de ventana y render --- // --- Configuración de ventana y render ---
void setFullscreenMode(bool mode = Options::video.fullscreen); // Establece el modo de video void setFullscreenMode(); // Establece el modo de pantalla completa
void toggleFullscreen(); // Cambia entre pantalla completa y ventana void toggleFullscreen(); // Cambia entre pantalla completa y ventana
void setWindowZoom(int size); // Cambia el tamaño de la ventana void setWindowZoom(int size); // Cambia el tamaño de la ventana
bool decWindowSize(); // Reduce el tamaño de la ventana bool decWindowSize(); // Reduce el tamaño de la ventana
bool incWindowSize(); // Aumenta el tamaño de la ventana bool incWindowSize(); // Aumenta el tamaño de la ventana
void applySettings(); // Aplica los valores de las opciones void applySettings(); // Aplica los valores de las opciones
// --- Efectos visuales --- // --- Efectos visuales ---
void shake() { shake_effect_.enable(src_rect_, dst_rect_); } // Agita la pantalla void shake() { shake_effect_.enable(src_rect_, dst_rect_); } // Agita la pantalla
@@ -205,10 +205,10 @@ private:
void loadShaders(); // Carga el contenido del archivo GLSL void loadShaders(); // Carga el contenido del archivo GLSL
void initShaders(); // Inicializa los shaders void initShaders(); // Inicializa los shaders
void adjustWindowSize(); // Calcula el tamaño de la ventana void adjustWindowSize(); // Calcula el tamaño de la ventana
void getDisplayInfo(); // Obtiene información sobre la pantalla void getDisplayInfo(); // Obtiene información sobre la pantalla
void renderOverlays(); // Renderiza todos los overlays y efectos void renderOverlays(); // Renderiza todos los overlays y efectos
void renderAttenuate(); // Atenúa la pantalla void renderAttenuate(); // Atenúa la pantalla
void createText(); // Crea el objeto de texto void createText(); // Crea el objeto de texto
// --- Constructores y destructor --- // --- Constructores y destructor ---
Screen(); Screen();