begin rgfx5 text renderer

This commit is contained in:
a
2025-07-05 11:35:40 -04:00
parent 23fb596ff7
commit a44ecb9da7
2 changed files with 46 additions and 18 deletions

View File

@@ -7,6 +7,8 @@
#include "segment2.h" #include "segment2.h"
#pragma GCC diagnostic ignored "-Wunused-parameter"
/* /*
* RGFXHUD 5 * RGFXHUD 5
* Features 3D transforms for menu elements. * Features 3D transforms for menu elements.
@@ -28,14 +30,33 @@
static RgfxHud sRgfxHudBuffer[RGFX_HUD_LAYERS][RGFX_HUD_BUFFER_SIZE]; static RgfxHud sRgfxHudBuffer[RGFX_HUD_LAYERS][RGFX_HUD_BUFFER_SIZE];
static RgfxHud *sRgfxHudHead[RGFX_HUD_LAYERS] = { &sRgfxHudBuffer[0][0], &sRgfxHudBuffer[1][0], &sRgfxHudBuffer[2][0] }; static RgfxHud *sRgfxHudHead[RGFX_HUD_LAYERS] = { &sRgfxHudBuffer[0][0], &sRgfxHudBuffer[1][0], &sRgfxHudBuffer[2][0] };
#pragma GCC diagnostic ignored "-Wunused-parameter" static Texture *sRgfxClownfontCharMap[] = {
// platform independent assert };
static inline void debug_crash(char *s) { static Texture *sRgfxCursiveCharMap[] = {
RGFX_PRINTF(s);
CRASH; };
}
static Texture *sRgfxCursiveHdCharMap[] = {
};
static Texture *sRgfxFasttextCharMap[] = {
};
static Texture *sRgfxHelveticaCharMap[] = {
};
static RgfxFontProperties sRgfxFontProperties[RGFX_HUD_FONTS] = {
{ &sRgfxClownfontCharMap[0], { 16, 16 }, FALSE },
{ &sRgfxCursiveCharMap[0], { 8, 12 }, TRUE },
{ &sRgfxCursiveHdCharMap[0], { 8, 12 }, TRUE },
{ &sRgfxFasttextCharMap[0], { 8, 8 }, FALSE },
{ &sRgfxHelveticaCharMap[0], { 10, 10 }, FALSE },
};
static RgfxHud *alloc_hud(u8 layer) { static RgfxHud *alloc_hud(u8 layer) {
n64_assert((u32)sRgfxHudHead[layer] <= (u32)&sRgfxHudBuffer[layer] + RGFX_HUD_BUFFER_SIZE); n64_assert((u32)sRgfxHudHead[layer] <= (u32)&sRgfxHudBuffer[layer] + RGFX_HUD_BUFFER_SIZE);
@@ -171,7 +192,7 @@ static inline f32 get_true_scale(RgfxHud *c, f32 s) {
return ret; return ret;
} }
static inline void apply_parent_transform(RgfxHud *c) { static void apply_parent_transform(RgfxHud *c) {
Mtx *matrix; Mtx *matrix;
if (c->parent != NULL) { if (c->parent != NULL) {
apply_parent_transform(c->parent); apply_parent_transform(c->parent);
@@ -202,17 +223,6 @@ static inline void apply_parent_transform(RgfxHud *c) {
} }
} }
void print_mtx(char *title, const Mtx *mtx) {
n64_printf("%s mtx\n", title);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
n64_printf("0x%08x ", mtx->m[i][j]);
}
n64_printf("\n");
}
n64_printf("\n");
}
static void rgfx_draw_box(RgfxHud *c) { static void rgfx_draw_box(RgfxHud *c) {
s16 x = get_true_x(c, 0); s16 x = get_true_x(c, 0);
s16 y = get_true_y(c, 0); s16 y = get_true_y(c, 0);
@@ -324,6 +334,15 @@ static void rgfx_draw_box(RgfxHud *c) {
gSPDisplayList(MASTERDL, dl_hud_img_end); gSPDisplayList(MASTERDL, dl_hud_img_end);
} }
s16 get_text_width(RgfxHud *c) {
switch (c->d.txt.font) {
}
}
// scale 1.0f is equal to a height of 16px
// if integer scaling is detected and we are NOT using 3d otherwise, fallback to texture rect
static void rgfx_draw_text(RgfxHud *c) { static void rgfx_draw_text(RgfxHud *c) {
if (is_2d_element(c)) { // we are using texture rectangles if (is_2d_element(c)) { // we are using texture rectangles
} else { // we are using ortho triangles } else { // we are using ortho triangles

View File

@@ -5,6 +5,8 @@
#define RGFX_HUD_BUFFER_SIZE 128 #define RGFX_HUD_BUFFER_SIZE 128
#define RGFX_HUD_LAYERS 3 #define RGFX_HUD_LAYERS 3
#define RGFX_HUD_FONTS 5
typedef enum { typedef enum {
RGFX_BOX, RGFX_BOX,
RGFX_TEXT, RGFX_TEXT,
@@ -17,10 +19,17 @@ typedef enum {
typedef enum { typedef enum {
RGFX_FONT_CLOWNFONT, RGFX_FONT_CLOWNFONT,
RGFX_FONT_CURSIVE, RGFX_FONT_CURSIVE,
RGFX_FONT_CURSIVE_HD,
RGFX_FONT_FASTTEXT, RGFX_FONT_FASTTEXT,
RGFX_FONT_HELVETICA RGFX_FONT_HELVETICA
} RgfxFont; } RgfxFont;
typedef struct {
Texture **charMap;
u8 size[2];
u8 flipped; // vanilla cursive font
} RgfxFontProperties;
typedef struct { typedef struct {
s16 sX, sY; s16 sX, sY;
u8 color[4]; u8 color[4];