This commit is contained in:
2026-09-12 13:05:38 -05:00
parent 311cf7534e
commit cc409912e6

51
glue.c
View File

@@ -46,7 +46,7 @@ ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file,
} }
void *filebuf = malloc(filesize); void *filebuf = malloc(filesize);
SFT sft = { .flags = 0 }; SFT sft = { .flags = SFT_DOWNWARD_Y };
ALLEGRO_FONT *f = NULL; ALLEGRO_FONT *f = NULL;
ALLEGRO_BITMAP *gtex = NULL; ALLEGRO_BITMAP *gtex = NULL;
int result = 0; int result = 0;
@@ -57,7 +57,7 @@ ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file,
al_get_config_value(system_cfg, "ttf", "cache_text"); al_get_config_value(system_cfg, "ttf", "cache_text");
if (!cache_text_str) { if (!cache_text_str) {
ALLEGRO_ERROR("No characters defined in cache_text! Using defaults\n"); ALLEGRO_ERROR("No characters defined in cache_text! Using defaults\n");
cache_text_str = "fart"; cache_text_str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
} }
// read font file // read font file
@@ -79,13 +79,15 @@ ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file,
FAIL; FAIL;
} }
// convert glyphs into textures todo // convert glyphs into textures
uint16_t woff = 1, hoff = 0, hmax = 2048; #define wmax (int32_t)1024
gtex = al_create_bitmap(2048, hmax); int32_t woff = 1, hoff = 1, hmax = 128; // signed to calculate difference at texture edges
gtex = al_create_bitmap(wmax, hmax);
al_set_target_bitmap(gtex); al_set_target_bitmap(gtex);
al_clear_to_color(al_map_rgba(0, 0, 0, 255)); al_clear_to_color(al_map_rgba(0, 0, 0, 0)); // todo invert alpha at final pass
unsigned int i = 0; unsigned int i = 0;
const unsigned int len = strlen(cache_text_str); const unsigned int len = strlen(cache_text_str);
unsigned int lh = 0;
while (i < len) { while (i < len) {
ALLEGRO_INFO("generating glyph for %c\n", cache_text_str[i]); ALLEGRO_INFO("generating glyph for %c\n", cache_text_str[i]);
SFT_Glyph glyph; SFT_Glyph glyph;
@@ -97,24 +99,43 @@ ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file,
ALLEGRO_INFO("got glyph\n"); ALLEGRO_INFO("got glyph\n");
if (0 > sft_gmetrics(&sft, glyph, &geom)) goto glyph_lookup_fail; if (0 > sft_gmetrics(&sft, glyph, &geom)) goto glyph_lookup_fail;
ALLEGRO_INFO("got geom\n"); ALLEGRO_INFO("got geom\n");
//if ((hmax - hoff) < geom.minWidth) { if (lh < geom.minHeight) lh = geom.minHeight;
// todo wrap glyphs, grow bmp if ((wmax - woff) < geom.minWidth) {
//} hoff += lh + 1;
block = woff = 1;
al_lock_bitmap_region(gtex, woff, hoff, geom.minWidth, geom.minHeight, }
ALLEGRO_PIXEL_FORMAT_SINGLE_CHANNEL_8, ALLEGRO_LOCK_READWRITE); if ((hmax - hoff) < (geom.minHeight + abs(geom.yOffset))) {
ALLEGRO_INFO("got lock\n"); ALLEGRO_WARN("ran out of room! growing glyph texture\n");
gtex = grow_bitmap(gtex, hmax);
al_set_target_bitmap(gtex);
hmax *= 2;
}
img.width = geom.minWidth; img.width = geom.minWidth;
img.height = geom.minHeight; img.height = geom.minHeight;
img.pixels = malloc(img.width * img.height); img.pixels = malloc(img.width * img.height);
if (!img.pixels) goto glyph_lookup_oom; if (!img.pixels) goto glyph_lookup_oom;
if (0 > sft_render(&sft, glyph, img)) goto glyph_lookup_fail; if (0 > sft_render(&sft, glyph, img)) goto glyph_lookup_fail;
ALLEGRO_INFO("got raster\n"); ALLEGRO_INFO("got raster\n");
free(fuck); block =
// todo copy bytes to texture al_lock_bitmap_region(gtex, woff, hoff, geom.minWidth, geom.minHeight + abs(geom.yOffset),
ALLEGRO_PIXEL_FORMAT_SINGLE_CHANNEL_8, ALLEGRO_LOCK_WRITEONLY);
assert(block->pixel_size == 1);
ALLEGRO_INFO("got vram lock\n");
int row = 0; // should not be signed!!!!! C programmers are fucking assholes!
uint8_t* dest = (uint8_t*)block->data + block->pitch * (geom.minHeight+geom.yOffset);
while (row < img.height) {
memcpy(
dest + block->pitch * row,
(uint8_t*)img.pixels + img.width * row,
img.width
);
row++;
}
free(img.pixels);
al_unlock_bitmap(gtex); al_unlock_bitmap(gtex);
ALLEGRO_INFO("blit raster to vram\n"); ALLEGRO_INFO("blit raster to vram\n");
woff += geom.minWidth + 1;
i++; continue; i++; continue;
glyph_lookup_oom: glyph_lookup_oom: