Skip to content

Commit 409dfa6

Browse files
committed
Adjust fonts for hi-res mode
1 parent 7eeb6c7 commit 409dfa6

File tree

7 files changed

+68
-33
lines changed

7 files changed

+68
-33
lines changed

Makefile

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,15 @@ PNG_FILES := $(wildcard $(PNG_DIR)/*.png)
5151
SPRITE_FILES := $(patsubst $(PNG_DIR)/%.png,$(SPRITE_DIR)/%.sprite,$(PNG_FILES))
5252
SPRITE_MANIFEST_TXT := $(PNG_DIR)/manifest.txt
5353

54+
# Font files
55+
FONT_DIR := $(RESOURCES_DIR)/fonts
56+
FONT64_DIR := $(N64_MKDFS_ROOT)/fonts
57+
FONT64_FILES := $(FONT64_DIR)/at01-1x.font64 $(FONT64_DIR)/at01-2x.font64
58+
5459
# Build artifacts
5560
DFS_FILE := $(BUILD_DIR)/$(N64_ROM_NAME).dfs
5661
LINKED_OBJS := $(BUILD_DIR)/$(N64_ROM_NAME).elf
5762

58-
# LibDragon tools
59-
N64_AUDIOCONV ?= $(N64_BINDIR)/audioconv64
60-
N64_MKSPRITE ?= $(N64_BINDIR)/mksprite
61-
6263
#
6364
# Compilation pipeline
6465
#
@@ -88,16 +89,30 @@ $(WAV64_DIR)/%.wav64: $(WAV_DIR)/%.wav
8889
@echo " [SFX] $<"
8990
$(N64_AUDIOCONV) -o "$(WAV64_DIR)" "$<" $(REDIRECT_STDOUT)
9091

92+
# Fonts (1x for low-res, 2x for high-res)
93+
FONT64_SIZE_1x := 16
94+
FONT64_SIZE_2x := 32
95+
FONT64_OUTLINE_1x := 1
96+
FONT64_OUTLINE_2x := 2
97+
98+
# Disable parallel builds for font generation to prevent race conditions
99+
.NOTPARALLEL: $(FONT64_FILES)
100+
101+
$(FONT64_DIR)/at01-%.font64: $(FONT_DIR)/at01.ttf
102+
@mkdir -p "$(dir $@)"
103+
@echo " [FONT] $< ($*)"
104+
$(N64_MKFONT) --size $(FONT64_SIZE_$*) --outline $(FONT64_OUTLINE_$*) --range 20-7F -o "$(FONT64_DIR)" "$<" $(REDIRECT_STDOUT)
105+
@mv "$(FONT64_DIR)/at01.font64" "$@"
106+
91107
# Filesystem
92-
$(DFS_FILE): $(SPRITE_FILES) $(WAV64_FILES)
108+
$(DFS_FILE): $(SPRITE_FILES) $(WAV64_FILES) $(FONT64_FILES)
93109

94110
#
95111
# Housekeeping
96112
#
97113

98114
clean:
99115
rm -Rf "$(BUILD_DIR)" *.z64
100-
git restore '*.z64'
101116
.PHONY: clean
102117

103118
# Include compiler-generated dependency files

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ This project's source code is [BSD licensed](./LICENSE.txt?raw=true) (c) 2017-20
102102
The graphic and sound assets are subject to the original work's copyright: [Flappy Bird (c) 2013 .Gears](https://www.dotgears.com/apps/app_flappy.html)<br />
103103
These assets are used for non-commercial purposes with love, care, and respect, but without permission.
104104

105+
The [at01 font by GrafxKid](https://grafxkid.itch.io/at01) is [Public Domain (CC0 1.0)](https://creativecommons.org/public-domain/cc0/).
106+
105107
LibDragon is [Unlicensed public domain software](https://github.com/DragonMinded/libdragon/blob/trunk/LICENSE.md?raw=true).
106108

107109
"Nintendo 64" is a registered trademark of Nintendo used for informational purposes without permission.

resources/fonts/at01.ttf

22.8 KB
Binary file not shown.

src/fps.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,16 @@ void fps_init(void)
4343
{
4444
memset(&fps, 0, sizeof fps);
4545
FPS_TEXT_COLOR = RGBA32(0x00, 0x00, 0x00, 0xFF);
46-
/* Setup font style for FPS text */
47-
rdpq_font_t *font = (rdpq_font_t *)rdpq_text_get_font(FONT_DEBUG);
48-
if (font)
46+
/* Setup font style for FPS text (both 1x and 2x fonts) */
47+
rdpq_font_t *font_1x = (rdpq_font_t *)rdpq_text_get_font(FONT_AT01);
48+
rdpq_font_t *font_2x = (rdpq_font_t *)rdpq_text_get_font(FONT_AT01_2X);
49+
if (font_1x)
4950
{
50-
rdpq_font_style(font, 0, &(rdpq_fontstyle_t){ .color = FPS_TEXT_COLOR });
51+
rdpq_font_style(font_1x, 0, &(rdpq_fontstyle_t){ .color = FPS_TEXT_COLOR });
52+
}
53+
if (font_2x)
54+
{
55+
rdpq_font_style(font_2x, 0, &(rdpq_fontstyle_t){ .color = FPS_TEXT_COLOR });
5156
}
5257
}
5358

@@ -101,12 +106,14 @@ void fps_draw(void)
101106
if (!fps.should_draw) return;
102107

103108
const ticks_t ticks = timer_ticks();
109+
const int font_id = gfx->highres ? FONT_AT01_2X : FONT_AT01;
110+
const int line_height = gfx->highres ? 26 : 13;
104111

105-
rdpq_text_printf(NULL, FONT_DEBUG, 10, gfx->height - 33,
112+
rdpq_text_printf(NULL, font_id, 10, gfx->height - (line_height * 2 + 7),
106113
"FPS: %05.2f, Frame: %u, Miss: %u",
107114
fps.average_fps, fps.total_frames, fps.total_misses);
108115

109-
rdpq_text_printf(NULL, FONT_DEBUG, 10, gfx->height - 20,
116+
rdpq_text_printf(NULL, font_id, 10, gfx->height - (line_height + 7),
110117
"Milli: %llu, Tick: %llu",
111118
ticks / TICKS_PER_MS, ticks);
112119
}

src/gfx.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
gfx_t *gfx;
1313

14-
/* Font IDs for RDPQ text rendering */
15-
#define FONT_DEBUG 1
16-
1714
void gfx_init(void)
1815
{
1916
/* Setup state */
@@ -24,9 +21,11 @@ void gfx_init(void)
2421
/* Set up the display and RDP subsystems */
2522
display_init(RESOLUTION_320x240, DEPTH_16_BPP, 3, GAMMA_NONE, FILTERS_RESAMPLE);
2623
rdpq_init();
27-
/* Setup debug font for text rendering */
28-
rdpq_font_t *debug_font = rdpq_font_load_builtin(FONT_BUILTIN_DEBUG_MONO);
29-
rdpq_text_register_font(FONT_DEBUG, debug_font);
24+
/* Load custom fonts for text rendering (1x and 2x for high-res) */
25+
rdpq_font_t *font_1x = rdpq_font_load("rom:/fonts/at01-1x.font64");
26+
rdpq_font_t *font_2x = rdpq_font_load("rom:/fonts/at01-2x.font64");
27+
rdpq_text_register_font(FONT_AT01, font_1x);
28+
rdpq_text_register_font(FONT_AT01_2X, font_2x);
3029
/* Cache display dimensions */
3130
gfx->width = display_get_width();
3231
gfx->height = display_get_height();

src/gfx.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
#include "system.h"
1414

1515
/* Font IDs for RDPQ text rendering */
16-
#define FONT_DEBUG 1
16+
#define FONT_AT01 1
17+
#define FONT_AT01_2X 2
1718

1819
/* Graphics definitions */
1920

src/ui.c

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,18 @@ static void ui_set_time_mode(ui_t *ui, bg_time_mode_t time_mode)
202202
ui->text_color = UI_DARK_COLOR;
203203
ui->shadow_color = UI_LIGHT_COLOR;
204204
}
205-
/* Update font styles for current time mode */
206-
rdpq_font_t *font = (rdpq_font_t *)rdpq_text_get_font(FONT_DEBUG);
207-
if (font)
205+
/* Update font styles for current time mode (both 1x and 2x fonts) */
206+
rdpq_font_t *font_1x = (rdpq_font_t *)rdpq_text_get_font(FONT_AT01);
207+
rdpq_font_t *font_2x = (rdpq_font_t *)rdpq_text_get_font(FONT_AT01_2X);
208+
if (font_1x)
208209
{
209-
rdpq_font_style(font, UI_STYLE_SHADOW, &(rdpq_fontstyle_t){ .color = ui->shadow_color });
210-
rdpq_font_style(font, UI_STYLE_TEXT, &(rdpq_fontstyle_t){ .color = ui->text_color });
210+
rdpq_font_style(font_1x, UI_STYLE_SHADOW, &(rdpq_fontstyle_t){ .color = ui->shadow_color });
211+
rdpq_font_style(font_1x, UI_STYLE_TEXT, &(rdpq_fontstyle_t){ .color = ui->text_color });
212+
}
213+
if (font_2x)
214+
{
215+
rdpq_font_style(font_2x, UI_STYLE_SHADOW, &(rdpq_fontstyle_t){ .color = ui->shadow_color });
216+
rdpq_font_style(font_2x, UI_STYLE_TEXT, &(rdpq_fontstyle_t){ .color = ui->text_color });
211217
}
212218
}
213219

@@ -421,37 +427,42 @@ static void ui_logo_draw(const ui_t *ui)
421427
.scale_y = gfx->scale,
422428
});
423429

430+
/* Select font and character width based on resolution */
431+
const int font_id = gfx->highres ? FONT_AT01_2X : FONT_AT01;
432+
const int char_w = gfx->highres ? 10 : 5;
433+
const int shadow_offset = gfx->highres ? 2 : 1;
434+
424435
const char *const credit1_str = "Game by .GEARS";
425-
const int credit1_w = strlen(credit1_str) * 6;
436+
const int credit1_w = strlen(credit1_str) * char_w;
426437
const int credit1_x = center_x - (credit1_w / 2);
427438
const int credit1_y = gfx->height - GFX_SCALE(80);
428439

429440
const char *const credit2_str = "N64 Port by Meeq";
430-
const int credit2_w = strlen(credit2_str) * 6;
441+
const int credit2_w = strlen(credit2_str) * char_w;
431442
const int credit2_x = center_x - (credit2_w / 2);
432443
const int credit2_y = gfx->height - GFX_SCALE(62);
433444

434445
const char *const version_str = ROM_VERSION;
435-
const int version_w = strlen(version_str) * 6;
446+
const int version_w = strlen(version_str) * char_w;
436447
const int version_x = gfx->width - GFX_SCALE(32) - version_w;
437448
const int version_y = gfx->height - GFX_SCALE(32);
438449

439450
/* Draw a shadow under the text */
440451
rdpq_textparms_t shadow_parms = { .style_id = UI_STYLE_SHADOW };
441-
rdpq_text_print(&shadow_parms, FONT_DEBUG, credit1_x + 1, credit1_y + 1, credit1_str);
442-
rdpq_text_print(&shadow_parms, FONT_DEBUG, credit2_x + 1, credit2_y + 1, credit2_str);
452+
rdpq_text_print(&shadow_parms, font_id, credit1_x + shadow_offset, credit1_y + shadow_offset, credit1_str);
453+
rdpq_text_print(&shadow_parms, font_id, credit2_x + shadow_offset, credit2_y + shadow_offset, credit2_str);
443454
if (version_w)
444455
{
445-
rdpq_text_print(&shadow_parms, FONT_DEBUG, version_x + 1, version_y + 1, version_str);
456+
rdpq_text_print(&shadow_parms, font_id, version_x + shadow_offset, version_y + shadow_offset, version_str);
446457
}
447458

448459
/* Draw the same text on top of the shadow */
449460
rdpq_textparms_t text_parms = { .style_id = UI_STYLE_TEXT };
450-
rdpq_text_print(&text_parms, FONT_DEBUG, credit1_x, credit1_y, credit1_str);
451-
rdpq_text_print(&text_parms, FONT_DEBUG, credit2_x, credit2_y, credit2_str);
461+
rdpq_text_print(&text_parms, font_id, credit1_x, credit1_y, credit1_str);
462+
rdpq_text_print(&text_parms, font_id, credit2_x, credit2_y, credit2_str);
452463
if (version_w)
453464
{
454-
rdpq_text_print(&text_parms, FONT_DEBUG, version_x, version_y, version_str);
465+
rdpq_text_print(&text_parms, font_id, version_x, version_y, version_str);
455466
}
456467
}
457468

0 commit comments

Comments
 (0)