g
This commit is contained in:
51
glue.c
51
glue.c
@@ -46,7 +46,7 @@ ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file,
|
||||
}
|
||||
void *filebuf = malloc(filesize);
|
||||
|
||||
SFT sft = { .flags = 0 };
|
||||
SFT sft = { .flags = SFT_DOWNWARD_Y };
|
||||
ALLEGRO_FONT *f = NULL;
|
||||
ALLEGRO_BITMAP *gtex = NULL;
|
||||
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");
|
||||
if (!cache_text_str) {
|
||||
ALLEGRO_ERROR("No characters defined in cache_text! Using defaults\n");
|
||||
cache_text_str = "fart";
|
||||
cache_text_str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
|
||||
}
|
||||
|
||||
// read font file
|
||||
@@ -79,13 +79,15 @@ ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file,
|
||||
FAIL;
|
||||
}
|
||||
|
||||
// convert glyphs into textures todo
|
||||
uint16_t woff = 1, hoff = 0, hmax = 2048;
|
||||
gtex = al_create_bitmap(2048, hmax);
|
||||
// convert glyphs into textures
|
||||
#define wmax (int32_t)1024
|
||||
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_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;
|
||||
const unsigned int len = strlen(cache_text_str);
|
||||
unsigned int lh = 0;
|
||||
while (i < len) {
|
||||
ALLEGRO_INFO("generating glyph for %c\n", cache_text_str[i]);
|
||||
SFT_Glyph glyph;
|
||||
@@ -97,24 +99,43 @@ ALLEGRO_FONT *al_load_ttf_font_f(ALLEGRO_FILE *file,
|
||||
ALLEGRO_INFO("got glyph\n");
|
||||
if (0 > sft_gmetrics(&sft, glyph, &geom)) goto glyph_lookup_fail;
|
||||
ALLEGRO_INFO("got geom\n");
|
||||
//if ((hmax - hoff) < geom.minWidth) {
|
||||
// todo wrap glyphs, grow bmp
|
||||
//}
|
||||
block =
|
||||
al_lock_bitmap_region(gtex, woff, hoff, geom.minWidth, geom.minHeight,
|
||||
ALLEGRO_PIXEL_FORMAT_SINGLE_CHANNEL_8, ALLEGRO_LOCK_READWRITE);
|
||||
ALLEGRO_INFO("got lock\n");
|
||||
if (lh < geom.minHeight) lh = geom.minHeight;
|
||||
if ((wmax - woff) < geom.minWidth) {
|
||||
hoff += lh + 1;
|
||||
woff = 1;
|
||||
}
|
||||
if ((hmax - hoff) < (geom.minHeight + abs(geom.yOffset))) {
|
||||
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.height = geom.minHeight;
|
||||
img.pixels = malloc(img.width * img.height);
|
||||
if (!img.pixels) goto glyph_lookup_oom;
|
||||
if (0 > sft_render(&sft, glyph, img)) goto glyph_lookup_fail;
|
||||
ALLEGRO_INFO("got raster\n");
|
||||
free(fuck);
|
||||
// todo copy bytes to texture
|
||||
block =
|
||||
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);
|
||||
ALLEGRO_INFO("blit raster to vram\n");
|
||||
|
||||
woff += geom.minWidth + 1;
|
||||
i++; continue;
|
||||
|
||||
glyph_lookup_oom:
|
||||
|
||||
Reference in New Issue
Block a user