From 5ba251b4ceb43ac057c4bc449918857437470763 Mon Sep 17 00:00:00 2001 From: Linkatplug Date: Sat, 5 Dec 2026 12:55:24 +0100 Subject: [PATCH] =?UTF-8?q?=C3=89cran=20large=20:=20bords=20remplis=20par?= =?UTF-8?q?=20l'image=20flout=C3=A9e=20(d=C3=A9sactivable=20dans=20F12)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - gfx_gl.c : quand l'image du jeu ne couvre pas la sortie (16:9, 21:9…), un fond est dessiné dessous : l'image du jeu réduite à 80×50 sur le processeur (moyenne par blocs, flou en boîte de rayon 2, assombrie à 55 %), étirée pour couvrir l'écran et lissée par 9 lectures bilinéaires (FS_BACKDROP). Calcul seulement quand l'image change ; coût GPU négligeable. - Réglage display.wide_fill (1 par défaut), menu F12 « Bords flous (écran large) ». Lignes du menu à 30 px pour la place. - docs/SETTINGS.md ; ROADMAP : écran large coché. Co-Authored-By: Claude Opus 5.5 --- docs/ROADMAP.en.md | 2 +- docs/ROADMAP.md | 2 +- docs/SETTINGS.md | 2 ++ runtime/gfx.h | 3 ++ runtime/gfx_gl.c | 85 ++++++++++++++++++++++++++++++++++++++++++++-- runtime/host_sdl.c | 1 + runtime/menu.c | 13 ++++--- runtime/menu.h | 1 + 8 files changed, 100 insertions(+), 9 deletions(-) diff --git a/docs/ROADMAP.en.md b/docs/ROADMAP.en.md index a4634b0..03d8ac4 100644 --- a/docs/ROADMAP.en.md +++ b/docs/ROADMAP.en.md @@ -43,7 +43,7 @@ INTRO.EXE stays local (`build/`). Mods replace files at runtime, never touching - [x] **Original ↔ HD toggle in game with F10**, with a crossfade (same as "HD pack" in F12, saved in `hd_pack`). The game only uses F10 in debug mode: the host intercepts it and does not pass it on -- [ ] **Widescreen without black bars**: sides filled with a blurred background or an illustration +- [x] **Widescreen without black bars**: sides filled with a blurred background or an illustration - [ ] **Upscaled FLC cutscenes** - [ ] Game icon: `tucker.exe` (`assets/icon/dtr.rc` resource compiled with `rc` in `build.bat`) and window (`SDL_SetWindowIcon` with `assets/icon/dtr-256.png`). The launcher already has it diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 39ad9c8..39fff54 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -45,7 +45,7 @@ jamais modifier les originaux. - [x] **Basculement original ↔ HD en jeu avec F10**, avec un fondu (même effet que « Pack HD » dans F12, enregistré dans `hd_pack`). Le jeu n'utilise F10 qu'en mode débogage : l'hôte l'intercepte et ne la transmet pas -- [ ] **Écran large sans bandes noires** : bords remplis par le décor flouté ou une illustration +- [x] **Écran large sans bandes noires** : bords remplis par le décor flouté ou une illustration - [ ] **Cinématiques FLC agrandies** - [ ] Police HD pour les textes et les sous-titres - [ ] Icône du jeu : `tucker.exe` (ressource `assets/icon/dtr.rc` compilée avec `rc` dans `build.bat`) diff --git a/docs/SETTINGS.md b/docs/SETTINGS.md index b76549e..57f263d 100644 --- a/docs/SETTINGS.md +++ b/docs/SETTINGS.md @@ -31,6 +31,7 @@ window_height=0 filter=xbr aspect_43=1 vsync=0 +wide_fill=1 hd_pack=1 hd_decors=1 hd_sprites=1 @@ -60,6 +61,7 @@ disabled= | `filter` | `nearest`, `smooth`, `xbr`, `crt` | `nearest` | Filtre d'image (voir ci-dessous) | | `aspect_43` | `0` / `1` | `1` | `1` : image 320×200 étirée en 4:3, comme sur un écran VGA. `0` : pixels carrés (16:10) | | `vsync` | `0` / `1` | `0` | Synchronisation verticale | +| `wide_fill` | `0` / `1` | `1` | Écran large : les bords autour de l'image sont remplis par l'image du jeu floutée et assombrie au lieu de bandes noires (menu F12 : « Bords flous (écran large) ») | | `hd_pack` | `0` / `1` | `1` | Pack HD fourni par les mods (voir [MODS.md](MODS.md)) : interrupteur général des trois clés suivantes. Sans effet si aucun mod ne fournit d'images HD, et avec le filtre `crt` | | `hd_decors` | `0` / `1` | `1` | Décors HD du pack | | `hd_sprites` | `0` / `1` | `1` | Personnages, objets et curseur HD du pack (sprites) | diff --git a/runtime/gfx.h b/runtime/gfx.h index 97d5261..16991b7 100644 --- a/runtime/gfx.h +++ b/runtime/gfx.h @@ -18,6 +18,9 @@ void gfx_draw(int out_w, int out_h, int filter, int game_aspect_h, float veil, f int gfx_snapshot(int out_w, int out_h, int filter, int game_aspect_h); void gfx_snapshot_alpha(float a); +/* Écran large : bords remplis par l'image du jeu floutée et assombrie (1) au lieu de bandes noires (0) */ +void gfx_set_backdrop(int on); + /* Pack HD : jusqu'à GFX_HD_PARTS images de décor côte à côte, chacune couvrant 320×200 pixels d'origine */ #define GFX_HD_PARTS 4 int gfx_hd_load(int part, const uint32_t *argb, int w, int h); /* 0 si l'image est trop grande pour le GPU */ diff --git a/runtime/gfx_gl.c b/runtime/gfx_gl.c index c6e6a6c..f7b977e 100644 --- a/runtime/gfx_gl.c +++ b/runtime/gfx_gl.c @@ -97,6 +97,17 @@ static const char *FS_OVERLAY = FS_HEAD " o_color = vec4(c.rgb, c.a * u_alpha);\n" "}\n"; +/* Fond des bords en écran large : image du jeu réduite à BG_W × BG_H (floutée et assombrie sur le processeur), + * lissée encore par 9 lectures bilinéaires : le reste du flou ne coûte presque rien au GPU. */ +static const char *FS_BACKDROP = FS_HEAD + "void main() {\n" + " vec2 t = 1.0 / u_src_size;\n" + " vec3 c = vec3(0.0);\n" + " for (int y = -1; y <= 1; y++)\n" + " for (int x = -1; x <= 1; x++) c += texture(u_src, v_uv + vec2(float(x), float(y)) * t).rgb;\n" + " o_color = vec4(c / 9.0 * u_color.rgb, 1.0);\n" + "}\n"; + static const char *FS_SOLID = FS_HEAD "void main() { o_color = u_color; }\n"; @@ -232,7 +243,7 @@ static const char *FS_CRT = FS_HEAD "}\n"; /* ------------------------------------------------------------------ état */ -enum { PG_NEAREST, PG_SMOOTH, PG_XBR, PG_CRT, PG_OVERLAY, PG_SOLID, PG_HD, PG_SPR, PG_COUNT }; +enum { PG_NEAREST, PG_SMOOTH, PG_XBR, PG_CRT, PG_OVERLAY, PG_SOLID, PG_HD, PG_SPR, PG_BACKDROP, PG_COUNT }; typedef struct { GLuint id; GLint src, src_size, out_size, alpha, color, flip; } Prog; static float pass_flip = 1.f; /* -1 : la cible est une texture intermédiaire (lue ensuite à l'endroit) */ static Prog prog[PG_COUNT]; @@ -246,6 +257,11 @@ static int game_w = 320, game_h = 200; static GLuint tex_hd[GFX_HD_PARTS]; static int hd_w[GFX_HD_PARTS]; static struct { int active, parts, offset; float tint[3]; } hd; +#define BG_W 80 +#define BG_H 50 +#define BG_DARK 0.55f /* luminosité des bords */ +static GLuint tex_bg; +static int bg_on, bg_ok; static GLuint tex_panel[GFX_PANELS]; static int panel_ok[GFX_PANELS], panel_n; static GfxRun panel_runs[GFX_PANEL_RUNS]; @@ -313,7 +329,7 @@ static GLuint make_tex(int w, int h, GLint filter) { } int gfx_init(void) { - const char *const fs[PG_COUNT] = {FS_NEAREST, FS_SMOOTH, FS_XBR, FS_CRT, FS_OVERLAY, FS_SOLID, FS_HD, FS_SPR}; + const char *const fs[PG_COUNT] = {FS_NEAREST, FS_SMOOTH, FS_XBR, FS_CRT, FS_OVERLAY, FS_SOLID, FS_HD, FS_SPR, FS_BACKDROP}; int i; #define X(type, name) \ if (!(p_##name = (type)SDL_GL_GetProcAddress(#name))) { fprintf(stderr, "[gfx] fonction GL absente : %s\n", #name); return 0; } @@ -328,6 +344,7 @@ int gfx_init(void) { p_glGenVertexArrays(1, &vao); tex_game = make_tex(game_w, game_h, GL_LINEAR); tex_ovl = make_tex(MENU_W, MENU_H, GL_LINEAR); + tex_bg = make_tex(BG_W, BG_H, GL_LINEAR); tex_xbr = make_tex(game_w * XBR_SCALE, game_h * XBR_SCALE, GL_LINEAR); glGenTextures(1, &tex_mask); glBindTexture(GL_TEXTURE_2D, tex_mask); @@ -359,6 +376,7 @@ void gfx_shutdown(void) { if (tex_snap) glDeleteTextures(1, &tex_snap); if (tex_game) glDeleteTextures(1, &tex_game); if (tex_ovl) glDeleteTextures(1, &tex_ovl); + if (tex_bg) glDeleteTextures(1, &tex_bg); if (tex_xbr) glDeleteTextures(1, &tex_xbr); for (i = 0; i < GFX_HD_PARTS; i++) if (tex_hd[i]) glDeleteTextures(1, &tex_hd[i]); for (i = 0; i < GFX_PANELS; i++) if (tex_panel[i]) glDeleteTextures(1, &tex_panel[i]); @@ -367,9 +385,71 @@ void gfx_shutdown(void) { if (vao) p_glDeleteVertexArrays(1, &vao); } +/* fond des bords : moyenne par blocs de l'image du jeu (alpha ignoré : ce sont les couleurs d'origine), puis flou + * en boîte séparable de rayon 2 ; quelques milliers d'opérations par image, seulement quand l'image change */ +static void update_backdrop(const uint32_t *argb, int w, int h) { + static float acc[BG_H][BG_W][3], tmp[BG_H][BG_W][3]; + static uint32_t out[BG_W * BG_H]; + int bw = w / BG_W, bh = h / BG_H, x, y, c, k; + if (bw < 1 || bh < 1) return; + for (y = 0; y < BG_H; y++) + for (x = 0; x < BG_W; x++) { + float s[3] = {0, 0, 0}; + int i, j; + for (j = 0; j < bh; j++) + for (i = 0; i < bw; i++) { + uint32_t v = argb[(y * bh + j) * w + x * bw + i]; + s[0] += (float)(v >> 16 & 255); s[1] += (float)(v >> 8 & 255); s[2] += (float)(v & 255); + } + for (c = 0; c < 3; c++) acc[y][x][c] = s[c] / (float)(bw * bh); + } + for (y = 0; y < BG_H; y++) + for (x = 0; x < BG_W; x++) + for (c = 0; c < 3; c++) { + float s = 0; + for (k = -2; k <= 2; k++) s += acc[y][x + k < 0 ? 0 : x + k >= BG_W ? BG_W - 1 : x + k][c]; + tmp[y][x][c] = s / 5.f; + } + for (y = 0; y < BG_H; y++) + for (x = 0; x < BG_W; x++) { + uint32_t v = 0xff000000u; + for (c = 0; c < 3; c++) { + float s = 0; + for (k = -2; k <= 2; k++) s += tmp[y + k < 0 ? 0 : y + k >= BG_H ? BG_H - 1 : y + k][x][c]; + v |= (uint32_t)(s / 5.f * BG_DARK + 0.5f) << (16 - 8 * c); + } + out[y * BG_W + x] = v; + } + glBindTexture(GL_TEXTURE_2D, tex_bg); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, BG_W, BG_H, GL_BGRA, GL_UNSIGNED_BYTE, out); + bg_ok = 1; +} + void gfx_set_game(const uint32_t *argb, int w, int h) { glBindTexture(GL_TEXTURE_2D, tex_game); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_BYTE, argb); + if (bg_on) update_backdrop(argb, w, h); +} + +void gfx_set_backdrop(int on) { + if (!on) bg_ok = 0; + bg_on = on; +} + +/* bords : fond flou étiré pour couvrir toute la sortie (centré, rogné), sous l'image du jeu */ +static void draw_backdrop(int out_w, int out_h, int game_aspect_h) { + const Prog *p = &prog[PG_BACKDROP]; + double s = (double)out_w / 320.0 > (double)out_h / game_aspect_h ? (double)out_w / 320.0 : (double)out_h / game_aspect_h; + int w = (int)(320.0 * s + 0.5), h = (int)(game_aspect_h * s + 0.5); + glViewport((out_w - w) / 2, (out_h - h) / 2, w, h); + p_glUseProgram(p->id); + p_glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, tex_bg); + if (p->src >= 0) p_glUniform1i(p->src, 0); + if (p->src_size >= 0) p_glUniform2f(p->src_size, (float)BG_W, (float)BG_H); + if (p->flip >= 0) p_glUniform1f(p->flip, pass_flip); + p_glUniform4f(p->color, 1.f, 1.f, 1.f, 1.f); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } void gfx_set_overlay(const uint32_t *argb, int w, int h) { @@ -580,6 +660,7 @@ void gfx_draw(int out_w, int out_h, int filter, int game_aspect_h, float veil, f glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); if (target_fb) glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE); /* copie pour le fondu : reste opaque */ + if (bg_on && bg_ok && (g.w < out_w - 1 || g.h < out_h - 1)) draw_backdrop(out_w, out_h, game_aspect_h); if ((hd.active || panel_n || spr_n) && filter != FILTER_CRT) { if (hd.active) draw_hd(g, out_h); if (panel_n) draw_panel(g, out_h); diff --git a/runtime/host_sdl.c b/runtime/host_sdl.c index f2811e8..0d07893 100644 --- a/runtime/host_sdl.c +++ b/runtime/host_sdl.c @@ -153,6 +153,7 @@ static void apply_display(void) { } if (settings.vsync != done_vsync) SDL_GL_SetSwapInterval(settings.vsync ? 1 : 0); hd_set_enabled(settings.hd_pack && settings.hd_decors); + gfx_set_backdrop(settings.wide_fill); hd_set_panel_enabled(settings.hd_pack && settings.hd_panel); redraw = 1; done_scale = settings.window_scale; done_w = settings.window_width; done_h = settings.window_height; diff --git a/runtime/menu.c b/runtime/menu.c index 2c680bd..4201539 100644 --- a/runtime/menu.c +++ b/runtime/menu.c @@ -28,6 +28,7 @@ void settings_defaults(void) { settings.filter = FILTER_NEAREST; settings.aspect_43 = 1; settings.vsync = 0; + settings.wide_fill = 1; settings.hd_pack = 1; settings.hd_decors = 1; settings.hd_sprites = 1; @@ -55,6 +56,7 @@ static const struct { {"display", "filter", &settings.filter, 0, FILTER_COUNT - 1, filter_names}, {"display", "aspect_43", &settings.aspect_43, 0, 1, NULL}, {"display", "vsync", &settings.vsync, 0, 1, NULL}, + {"display", "wide_fill", &settings.wide_fill, 0, 1, NULL}, {"display", "hd_pack", &settings.hd_pack, 0, 1, NULL}, {"display", "hd_decors", &settings.hd_decors, 0, 1, NULL}, {"display", "hd_sprites", &settings.hd_sprites, 0, 1, NULL}, @@ -422,6 +424,7 @@ static Item items[] = { {"Taille de la fenêtre", IT_CHOICE, &res_index, 0, 0, 1, res_names}, /* liste : menu_open */ {"Filtre d'image", IT_CHOICE, &settings.filter, 0, FILTER_COUNT - 1, 1, filter_labels}, {"Format d'origine 4:3", IT_SWITCH, &settings.aspect_43, 0, 1, 1, NULL}, + {"Bords flous (écran large)", IT_SWITCH, &settings.wide_fill, 0, 1, 1, NULL}, {"Synchro verticale", IT_SWITCH, &settings.vsync, 0, 1, 1, NULL}, {"Pack HD (mods)", IT_SWITCH, &settings.hd_pack, 0, 1, 1, NULL}, {" Décors HD", IT_SWITCH, &settings.hd_decors, 0, 1, 1, NULL}, @@ -432,8 +435,8 @@ static Item items[] = { #define N_ITEMS ((int)(sizeof items / sizeof items[0])) #define FIRST_DISPLAY 4 #define ITEM_SCALE 5 -#define ITEM_HD 9 -#define ITEM_HD_LAST 12 /* Décors, personnages et objets, barre d'actions : sous l'interrupteur du pack */ +#define ITEM_HD 10 +#define ITEM_HD_LAST 13 /* Décors, personnages et objets, barre d'actions : sous l'interrupteur du pack */ static int sel, button, dragging = -1, last_mx = -1, last_my = -1; @@ -442,7 +445,7 @@ static int sel, button, dragging = -1, last_mx = -1, last_my = -1; #define PANEL_X1 810 #define PANEL_Y0 40 #define PANEL_Y1 700 -#define ROW_H 32 +#define ROW_H 30 #define CTRL_X0 (PANEL_X0 + 330) #define CTRL_X1 (PANEL_X1 - 44) #define SLIDER_X1 (CTRL_X1 - 84) @@ -452,7 +455,7 @@ static int sel, button, dragging = -1, last_mx = -1, last_my = -1; static int row_y(int i) { if (i < FIRST_DISPLAY) return 146 + i * ROW_H; - if (i < N_ITEMS - 1) return 316 + (i - FIRST_DISPLAY) * ROW_H; + if (i < N_ITEMS - 1) return 304 + (i - FIRST_DISPLAY) * ROW_H; return 618; } @@ -645,7 +648,7 @@ void menu_draw(uint32_t *px) { text(&font_title, PANEL_X0 + 44, PANEL_Y0 + 26, "Réglages", C_ACCENT, 255); round_rect(PANEL_X0 + 44, 114, PANEL_X1 - 44, 116, 1, C_BORDER, 255); text(&font_small, PANEL_X0 + 44, 124, "SON", C_MUTED, 255); - text(&font_small, PANEL_X0 + 44, 292, "AFFICHAGE", C_MUTED, 255); + text(&font_small, PANEL_X0 + 44, 280, "AFFICHAGE", C_MUTED, 255); for (i = 0; i < N_ITEMS; i++) { const Item *it = &items[i]; diff --git a/runtime/menu.h b/runtime/menu.h index 47b2d72..d0c5f9a 100644 --- a/runtime/menu.h +++ b/runtime/menu.h @@ -20,6 +20,7 @@ typedef struct { int filter; /* FILTER_* */ int aspect_43; /* 1 = 320×200 étiré en 4:3 comme sur un écran VGA, 0 = pixels carrés */ int vsync; /* 0/1 */ + int wide_fill; /* 0/1 : écran large, bords remplis par l'image floutée au lieu de bandes noires */ int hd_pack; /* 0/1 : pack HD des mods (interrupteur général des trois suivants) */ int hd_decors; /* 0/1 : décors HD */ int hd_sprites; /* 0/1 : personnages et objets HD (sprites) */