X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=font.h;h=eaba149b68d06bd7514fd9fc0b4d250ca06e3b2b;hb=1b522daa02f28128498b04def4d60b63e590d1f3;hp=4c7d8f46f1e09ad0a970bf13d34af0b8b22c6b20;hpb=d6171f1c56789b2ca79efa3313fbbf74a13bda7a;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/font.h b/font.h index 4c7d8f4..eaba149 100644 --- a/font.h +++ b/font.h @@ -32,8 +32,13 @@ VG_STATIC void font3d_load( font3d *font, const char *mdl_path, void *alloc ) vg_linear_clear( vg_mem.scratch ); mdl_load_mesh_block( &font->mdl, vg_mem.scratch ); - mdl_load_pack_block( &font->mdl, vg_mem.scratch ); - mdl_close( &font->mdl ); + + if( !mdl_arrcount( &font->mdl.textures ) ) + vg_fatal_exit_loop( "No texture in font file" ); + + mdl_texture *tex0 = mdl_arritm( &font->mdl.textures, 0 ); + void *data = vg_linear_alloc( vg_mem.scratch, tex0->file.pack_size ); + mdl_fread_pack_file( &font->mdl, &tex0->file, data ); vg_acquire_thread_sync(); { @@ -44,16 +49,16 @@ VG_STATIC void font3d_load( font3d *font, const char *mdl_path, void *alloc ) /* upload first texture */ font->texture = vg_tex2d_new(); - mdl_texture *tex0 = mdl_arritm( &font->mdl.textures, 0 ); vg_tex2d_set_error(); - vg_tex2d_qoi( mdl_arritm( &font->mdl.pack, tex0->file.pack_offset ), - tex0->file.pack_size, + vg_tex2d_qoi( data, tex0->file.pack_size, mdl_pstr( &font->mdl, tex0->file.pstr_path )); vg_tex2d_nearest(); vg_tex2d_repeat(); } vg_release_thread_sync(); + + mdl_close( &font->mdl ); } VG_STATIC void font3d_init(void) @@ -86,6 +91,17 @@ VG_STATIC void font3d_bind( font3d *font, camera *cam ) mesh_bind( &font->mesh ); } +VG_STATIC ent_glyph *font3d_glyph( font3d *font, u32 variant_id, u32 utf32 ) +{ + if( utf32 < font->info.glyph_utf32_base ) return NULL; + if( utf32 >= font->info.glyph_utf32_base+font->info.glyph_count) return NULL; + + u32 index = utf32 - font->info.glyph_utf32_base; + index += font->info.glyph_start; + index += font->info.glyph_count * variant_id; + return mdl_arritm( &font->glyphs, index ); +} + VG_STATIC void font3d_simple_draw( font3d *font, u32 variant_id, const char *text, camera *cam, m4x3f transform ) @@ -105,13 +121,8 @@ void font3d_simple_draw( font3d *font, u32 variant_id, const char *text, u32 c = text[i]; if(!c) break; - if( c < font->info.glyph_utf32_base ) continue; - if( c >= font->info.glyph_utf32_base+font->info.glyph_count) continue; - - u32 index = c - font->info.glyph_utf32_base; - index += font->info.glyph_start; - index += font->info.glyph_count * variant_id; - ent_glyph *glyph = mdl_arritm( &font->glyphs, index ); + ent_glyph *glyph = font3d_glyph( font, variant_id, c ); + if( !glyph ) continue; if( glyph->indice_count ){ shader_model_font_uOffset( offset ); @@ -129,13 +140,8 @@ float font3d_string_width( font3d *font, u32 variant_id, const char *text ) u32 c = text[i]; if(!c) break; - if( c < font->info.glyph_utf32_base ) continue; - if( c >= font->info.glyph_utf32_base+font->info.glyph_count) continue; - - u32 index = c - font->info.glyph_utf32_base; - index += font->info.glyph_start; - index += font->info.glyph_count * variant_id; - ent_glyph *glyph = mdl_arritm( &font->glyphs, index ); + ent_glyph *glyph = font3d_glyph( font, variant_id, c ); + if( !glyph ) continue; width += glyph->size[0]; }