From 770523ab089c20af6c7a27543479848714f30d08 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 15 Sep 2025 09:44:04 +0200 Subject: [PATCH] Implementar toggle debug display y mejorar transparencia del texto MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Añadir tecla H para activar/desactivar debug display - Debug display desactivado por defecto para interfaz limpia - Implementar procesamiento bitmap monocromo a RGBA32 con transparencia - Convertir fondo blanco original a pixels transparentes - Convertir texto negro original a pixels blancos para color mod - Configurar SDL_BLENDMODE_BLEND para transparencia correcta - Actualizar README con documentacion de tecla H y debug display - Conseguir texto flotante sin fondo negro para mejor legibilidad đŸ€– Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- README.md | 9 +++++++- source/external/dbgtxt.h | 46 +++++++++++++++++++++++++++++++++++++++- source/main.cpp | 39 ++++++++++++++++++++++------------ 3 files changed, 78 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 101d20f..7cf31be 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ | Tecla | Accion | |-------|--------| +| `H` | **Alternar debug display (FPS, V-Sync, valores fisica)** | | `V` | **Alternar V-Sync ON/OFF** | | `1-8` | Cambiar numero de pelotas (1, 10, 100, 500, 1K, 10K, 50K, 100K) | | `ESPACIO` | Impulsar todas las pelotas hacia arriba | @@ -24,9 +25,15 @@ ## 📊 Informacion en Pantalla +- **Centro**: Numero de pelotas activas en **blanco** (temporal) + +### Debug Display (Tecla `H`) + +Cuando se activa el debug display con la tecla `H`: + - **Esquina superior izquierda**: Estado V-Sync (VSYNC: ON/OFF) en **cian** - **Esquina superior derecha**: Contador FPS en tiempo real en **amarillo** -- **Centro**: Numero de pelotas activas en **blanco** (temporal) +- **Linea 3**: Valores fisica primera pelota (GRAV, VY, FLOOR) en **magenta** ## đŸ—ïž Estructura del Proyecto diff --git a/source/external/dbgtxt.h b/source/external/dbgtxt.h index 0b32c20..b9efa2c 100644 --- a/source/external/dbgtxt.h +++ b/source/external/dbgtxt.h @@ -10,12 +10,56 @@ void dbg_init(SDL_Renderer *renderer) { dbg_ren = renderer; Uint8 font[448] = {0x42, 0x4D, 0xC0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x01, 0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x18, 0xF3, 0x83, 0x83, 0xCF, 0x83, 0x87, 0x00, 0x00, 0xF3, 0x39, 0x39, 0xCF, 0x79, 0xF3, 0x00, 0x00, 0x01, 0xF9, 0x39, 0xCF, 0x61, 0xF9, 0x00, 0x00, 0x33, 0xF9, 0x03, 0xE7, 0x87, 0x81, 0x00, 0x00, 0x93, 0x03, 0x3F, 0xF3, 0x1B, 0x39, 0x00, 0x00, 0xC3, 0x3F, 0x9F, 0x39, 0x3B, 0x39, 0x00, 0x41, 0xE3, 0x03, 0xC3, 0x01, 0x87, 0x83, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xE7, 0x01, 0xC7, 0x81, 0x01, 0x83, 0x00, 0x00, 0xE7, 0x1F, 0x9B, 0xE7, 0x1F, 0x39, 0x00, 0x00, 0xE7, 0x8F, 0x39, 0xE7, 0x87, 0xF9, 0x00, 0x00, 0xC3, 0xC7, 0x39, 0xE7, 0xC3, 0xC3, 0x00, 0x00, 0x99, 0xE3, 0x39, 0xE7, 0xF1, 0xE7, 0x00, 0x00, 0x99, 0xF1, 0xB3, 0xC7, 0x39, 0xF3, 0x00, 0x00, 0x99, 0x01, 0xC7, 0xE7, 0x83, 0x81, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x83, 0xE7, 0x83, 0xEF, 0x39, 0x39, 0x00, 0x00, 0x39, 0xE7, 0x39, 0xC7, 0x11, 0x11, 0x00, 0x00, 0xF9, 0xE7, 0x39, 0x83, 0x01, 0x83, 0x00, 0x00, 0x83, 0xE7, 0x39, 0x11, 0x01, 0xC7, 0x00, 0x00, 0x3F, 0xE7, 0x39, 0x39, 0x29, 0x83, 0x00, 0x00, 0x33, 0xE7, 0x39, 0x39, 0x39, 0x11, 0x00, 0x00, 0x87, 0x81, 0x39, 0x39, 0x39, 0x39, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x39, 0x39, 0x83, 0x3F, 0x85, 0x31, 0x00, 0x00, 0x39, 0x31, 0x39, 0x3F, 0x33, 0x23, 0x00, 0x00, 0x29, 0x21, 0x39, 0x03, 0x21, 0x07, 0x00, 0x00, 0x01, 0x01, 0x39, 0x39, 0x39, 0x31, 0x00, 0x00, 0x01, 0x09, 0x39, 0x39, 0x39, 0x39, 0x00, 0x00, 0x11, 0x19, 0x39, 0x39, 0x39, 0x39, 0x00, 0x00, 0x39, 0x39, 0x83, 0x03, 0x83, 0x03, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xC1, 0x39, 0x81, 0x83, 0x31, 0x01, 0x00, 0x00, 0x99, 0x39, 0xE7, 0x39, 0x23, 0x3F, 0x00, 0x00, 0x39, 0x39, 0xE7, 0xF9, 0x07, 0x3F, 0x00, 0x00, 0x31, 0x01, 0xE7, 0xF9, 0x0F, 0x3F, 0x00, 0x00, 0x3F, 0x39, 0xE7, 0xF9, 0x27, 0x3F, 0x00, 0x00, 0x9F, 0x39, 0xE7, 0xF9, 0x33, 0x3F, 0x00, 0x00, 0xC1, 0x39, 0x81, 0xF9, 0x39, 0x3F, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x39, 0x03, 0xC3, 0x07, 0x01, 0x3F, 0x00, 0x00, 0x39, 0x39, 0x99, 0x33, 0x3F, 0x3F, 0x00, 0x00, 0x01, 0x39, 0x3F, 0x39, 0x3F, 0x3F, 0x00, 0x00, 0x39, 0x03, 0x3F, 0x39, 0x03, 0x03, 0x00, 0x00, 0x39, 0x39, 0x3F, 0x39, 0x3F, 0x3F, 0x00, 0x00, 0x93, 0x39, 0x99, 0x33, 0x3F, 0x3F, 0x00, 0x00, 0xC7, 0x03, 0xC3, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00}; - dbg_tex = SDL_CreateTextureFromSurface(dbg_ren, SDL_LoadBMP_IO(SDL_IOFromMem(font, 448), 1)); + + // Cargar surface del bitmap font + SDL_Surface* font_surface = SDL_LoadBMP_IO(SDL_IOFromMem(font, 448), 1); + if (font_surface != nullptr) + { + // Crear una nueva surface de 32 bits con canal alpha + SDL_Surface* rgba_surface = SDL_CreateSurface(font_surface->w, font_surface->h, SDL_PIXELFORMAT_RGBA8888); + if (rgba_surface != nullptr) + { + // Obtener pĂ­xeles de ambas surfaces + Uint8* src_pixels = (Uint8*)font_surface->pixels; + Uint32* dst_pixels = (Uint32*)rgba_surface->pixels; + + int width = font_surface->w; + int height = font_surface->h; + + // Procesar cada pĂ­xel + for (int y = 0; y < height; y++) + { + for (int x = 0; x < width; x++) + { + int byte_index = y * font_surface->pitch + (x / 8); + int bit_index = 7 - (x % 8); + + // Extraer bit del bitmap monocromo + bool is_white = (src_pixels[byte_index] >> bit_index) & 1; + + if (is_white) // Fondo blanco original -> transparente + { + dst_pixels[y * width + x] = 0x00000000; // Transparente + } + else // Texto negro original -> blanco opaco + { + dst_pixels[y * width + x] = 0xFFFFFFFF; // Blanco opaco + } + } + } + + dbg_tex = SDL_CreateTextureFromSurface(dbg_ren, rgba_surface); + SDL_DestroySurface(rgba_surface); + } + SDL_DestroySurface(font_surface); + } // Configurar filtro nearest neighbor para pĂ­xel perfect del texto if (dbg_tex != nullptr) { SDL_SetTextureScaleMode(dbg_tex, SDL_SCALEMODE_NEAREST); + // Configurar blend mode para transparencia normal + SDL_SetTextureBlendMode(dbg_tex, SDL_BLENDMODE_BLEND); } } diff --git a/source/main.cpp b/source/main.cpp index 58823d0..b265f84 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -47,6 +47,9 @@ std::string vsync_text = "VSYNC: ON"; // Texto del estado V-Sync Uint64 last_frame_time = 0; // Tiempo del Ășltimo frame en milisegundos float delta_time = 0.0f; // Tiempo transcurrido desde el Ășltimo frame en segundos +// Variables para Debug Display +bool show_debug = false; // Debug display desactivado por defecto + // Establece el texto en pantalla mostrando el nĂșmero de bolas actuales void setText() { @@ -224,6 +227,10 @@ void checkEvents() toggleVSync(); break; + case SDLK_H: + show_debug = !show_debug; + break; + case SDLK_1: scenario = 0; initBalls(scenario); @@ -311,21 +318,25 @@ void render() dbg_print(text_pos, 8, text.c_str(), 255, 255, 255); } - // Mostrar contador de FPS en esquina superior derecha - int fps_text_width = static_cast(fps_text.length() * 8); // 8 pĂ­xeles por carĂĄcter - int fps_x = SCREEN_WIDTH - fps_text_width - 8; // 8 pĂ­xeles de margen - dbg_print(fps_x, 8, fps_text.c_str(), 255, 255, 0); // Amarillo para distinguir - - // Mostrar estado V-Sync en esquina superior izquierda - dbg_print(8, 8, vsync_text.c_str(), 0, 255, 255); // Cian para distinguir - - // Debug: Mostrar valores de la primera pelota (si existe) - if (!balls.empty()) + // Debug display (solo si estĂĄ activado con tecla H) + if (show_debug) { - std::string debug_text = "GRAV: " + std::to_string(balls[0]->getGravityForce()) + - " VY: " + std::to_string(balls[0]->getVelocityY()) + - " FLOOR: " + (balls[0]->isOnFloor() ? "YES" : "NO"); - dbg_print(8, 24, debug_text.c_str(), 255, 0, 255); // Magenta para debug + // Mostrar contador de FPS en esquina superior derecha + int fps_text_width = static_cast(fps_text.length() * 8); // 8 pĂ­xeles por carĂĄcter + int fps_x = SCREEN_WIDTH - fps_text_width - 8; // 8 pĂ­xeles de margen + dbg_print(fps_x, 8, fps_text.c_str(), 255, 255, 0); // Amarillo para distinguir + + // Mostrar estado V-Sync en esquina superior izquierda + dbg_print(8, 8, vsync_text.c_str(), 0, 255, 255); // Cian para distinguir + + // Debug: Mostrar valores de la primera pelota (si existe) + if (!balls.empty()) + { + std::string debug_text = "GRAV: " + std::to_string(balls[0]->getGravityForce()) + + " VY: " + std::to_string(balls[0]->getVelocityY()) + + " FLOOR: " + (balls[0]->isOnFloor() ? "YES" : "NO"); + dbg_print(8, 24, debug_text.c_str(), 255, 0, 255); // Magenta para debug + } } SDL_RenderPresent(renderer);