Implementar toggle debug display y mejorar transparencia del texto

- 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 <noreply@anthropic.com>
This commit is contained in:
2025-09-15 09:44:04 +02:00
parent 393ad991a7
commit 770523ab08
3 changed files with 78 additions and 16 deletions

View File

@@ -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);
}
}

View File

@@ -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<int>(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<int>(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);