From: hgn Date: Wed, 26 Apr 2023 17:24:51 +0000 (+0100) Subject: font works X-Git-Url: https://harrygodden.com/git/?a=commitdiff_plain;h=c34dde859968ced3dc7e8dd7be29f676689813d3;p=carveJwlIkooP6JGAAIwe30JlM.git font works --- diff --git a/blender_export.py b/blender_export.py index 00c2de4..84dc3a7 100644 --- a/blender_export.py +++ b/blender_export.py @@ -467,6 +467,10 @@ cxr_graph_mapping = \ "Color": material_tex_image("tex_normal") } } + }, + "Emission": + { + "Color": material_tex_image("tex_diffuse") } } @@ -975,7 +979,7 @@ def sr_compile_fonts( collection ): font.glyph_start = glyph_count glyph_base = data.glyphs[0].utf32 - glyph_range = data.glyphs[-1].utf32 - glyph_base + glyph_range = data.glyphs[-1].utf32+1 - glyph_base font.glyph_utf32_base = glyph_base font.glyph_count = glyph_range diff --git a/ent_skateshop.c b/ent_skateshop.c index adccac5..a30fca9 100644 --- a/ent_skateshop.c +++ b/ent_skateshop.c @@ -3,6 +3,7 @@ #include "world.h" #include "player.h" +#include "gui.h" #define MAX_LOCAL_BOARDS 64 #define BILL_TIN_BOARDS 1 @@ -462,6 +463,8 @@ VG_STATIC void global_skateshop_preupdate(void) global_skateshop_exit(); return; } + + gui_helper_action( localplayer.input_use, "Select" ); } } diff --git a/font.h b/font.h index 9b5a13b..a7826f5 100644 --- a/font.h +++ b/font.h @@ -6,6 +6,51 @@ #include "camera.h" #include "shaders/model_font.h" + +enum efont_SRglyph{ + k_SRglyph_end = 0, /* control characters */ + k_SRglyph_ctrl_variant = 1, + k_SRglyph_mod_circle = 0x1e, /* surround and center next charater */ + k_SRglyph_mod_square = 0x1f, /* surround and center next character */ + k_SRglyph_ascii_min = 0x20, /* standard ascii */ + k_SRglyph_ascii_max = 0x7e, + k_SRglyph_ps4_square = 0x7f,/* playstation buttons */ + k_SRglyph_ps4_triangle = 0x80, + k_SRglyph_ps4_circle = 0x81, + k_SRglyph_ps4_cross = 0x82, + k_SRglyph_xb1_x = 0x83,/* xbox buttons */ + k_SRglyph_xb1_y = 0x84, + k_SRglyph_xb1_b = 0x85, + k_SRglyph_xb1_a = 0x86, + k_SRglyph_gen_ls = 0x87,/* generic gamepad */ + k_SRglyph_gen_lsh = 0x88, + k_SRglyph_gen_lsv = 0x89, + k_SRglyph_gen_lshv = 0x8a, + k_SRglyph_gen_rs = 0x8b, + k_SRglyph_gen_rsh = 0x8c, + k_SRglyph_gen_rsv = 0x8d, + k_SRglyph_gen_rshv = 0x8e, + k_SRglyph_gen_lt = 0x8f, + k_SRglyph_gen_rt = 0x90, + k_SRglyph_gen_lb = 0x91, + k_SRglyph_gen_rb = 0x92, + k_SRglyph_gen_left = 0x93, + k_SRglyph_gen_up = 0x94, + k_SRglyph_gen_right = 0x95, + k_SRglyph_gen_down = 0x96, + k_SRglyph_gen_options = 0x97, + k_SRglyph_gen_shareview = 0x98, + k_SRglyph_kbm_m0 = 0x99,/* mouse */ + k_SRglyph_kbm_m1 = 0x9a, + k_SRglyph_kbm_m01 = 0x9b, + k_SRglyph_kbm_m2 = 0x9c, + k_SRglyph_kbm_m2s = 0x9d, + k_SRglyph_kbm_shift = 0x9e,/* modifiers */ + k_SRglyph_kbm_ctrl = 0x9f, + k_SRglyph_kbm_alt = 0xa0, + k_SRglyph_kbm_space = 0xa1 +}; + typedef struct font3d font3d; struct font3d{ mdl_context mdl; @@ -89,7 +134,7 @@ VG_STATIC ent_glyph *font3d_glyph( font3d *font, u32 variant_id, u32 utf32 ) } VG_STATIC -void font3d_simple_draw( font3d *font, u32 variant_id, const char *text, +float font3d_simple_draw( font3d *font, u32 variant_id, const char *text, camera *cam, m4x3f transform ) { v3f offset; @@ -103,19 +148,55 @@ void font3d_simple_draw( font3d *font, u32 variant_id, const char *text, shader_model_font_uPvmPrev( prev_mtx ); shader_model_font_uMdl( transform ); + const u8 *u8str = (u8*)text; + for( int i=0;; i++ ){ - u32 c = text[i]; + u32 c = u8str[i]; if(!c) break; + if( c == k_SRglyph_ctrl_variant ){ + variant_id = u8str[i+1]; + continue; + } + ent_glyph *glyph = font3d_glyph( font, variant_id, c ); if( !glyph ) continue; if( glyph->indice_count ){ - shader_model_font_uOffset( offset ); - mesh_drawn( glyph->indice_start, glyph->indice_count ); + if( c == k_SRglyph_mod_square || c == k_SRglyph_mod_circle ){ + u32 c1 = u8str[i+1]; + if( c1 == '\0' ) break; + + ent_glyph *glyph1 = font3d_glyph( font, variant_id, c1 ); + + if( glyph1 ){ + if( glyph1->indice_count ){ + v3f v0; + v2_sub( glyph->size, glyph1->size, v0 ); + v2_muladds( offset, v0, -0.5f, v0 ); + v0[2] = 0.0f; + + shader_model_font_uOffset( v0 ); + mesh_drawn( glyph->indice_start, glyph->indice_count ); + + shader_model_font_uOffset( offset ); + mesh_drawn( glyph1->indice_start, glyph1->indice_count ); + offset[0] += glyph1->size[0]; + } + } + + i ++; + continue; + } + else{ + shader_model_font_uOffset( offset ); + mesh_drawn( glyph->indice_start, glyph->indice_count ); + } } offset[0] += glyph->size[0]; } + + return offset[0]; } VG_STATIC diff --git a/gui.h b/gui.h index cf381af..1e576e6 100644 --- a/gui.h +++ b/gui.h @@ -3,9 +3,88 @@ #include "font.h" -VG_STATIC void gui_example( void ) +struct{ + struct gui_helper{ + struct input_binding *bind; + const char *text; + } + helpers[4]; + u32 helper_count; +} +static gui; + +VG_STATIC +void gui_draw(void) +{ + camera ortho; + + float fl = 0.0f, + fr = vg.window_x, + fb = 0.0f, + ft = vg.window_y, + rl = 1.0f / (fr-fl), + tb = 1.0f / (ft-fb); + + m4x4_zero( ortho.mtx.p ); + ortho.mtx.p[0][0] = 2.0f * rl; + ortho.mtx.p[1][1] = 2.0f * tb; + ortho.mtx.p[3][0] = (fr + fl) * -rl; + ortho.mtx.p[3][1] = (ft + fb) * -tb; + ortho.mtx.p[3][3] = 1.0f; + m4x3_identity( ortho.transform ); + camera_update_view( &ortho ); + camera_finalize( &ortho ); + + if( gui.helper_count ){ + /* draw bottom bar */ + glEnable(GL_BLEND); + glDisable(GL_DEPTH_TEST); + glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); + glBlendEquation(GL_FUNC_ADD); + + shader_blitcolour_use(); + shader_blitcolour_uColour( (v4f){ 0.0f, 0.0f, 0.0f, 0.8f } ); + render_fsquad1(); + } + glDisable(GL_BLEND); + + font3d *font = &world_global.font; + font3d_bind( font, &ortho ); + + float dy = ft/0.79f, + scale = dy*0x1p-4f*0.75f; + + m4x3f mmdl; + v4f q; + m3x3_identity( mmdl ); + m3x3_scale( mmdl, (v3f){scale,scale,scale} ); + v3_zero( mmdl[3] ); + + float pad = dy*0x1p-4f*0.125f; + mmdl[3][0] = pad; + mmdl[3][1] = pad; + + for( u32 i=0; itext, &ortho, mmdl )+0.2f; + mmdl[3][0] += w*scale; + } + + gui.helper_count = 0; +} + +VG_STATIC +void gui_helper_action( struct input_binding *bind, const char *text ) { - + if( gui.helper_count >= vg_list_size(gui.helpers) ) + vg_fatal_error( "Too many helpers\n" ); + + struct gui_helper *helper = &gui.helpers[ gui.helper_count ++ ]; + helper->bind = bind; + helper->text = text; } #endif /* GUI_H */ diff --git a/models_src/rs_font.mdl b/models_src/rs_font.mdl index cd55971..d1049e3 100644 Binary files a/models_src/rs_font.mdl and b/models_src/rs_font.mdl differ diff --git a/player.h b/player.h index 72c26ed..d21212b 100644 --- a/player.h +++ b/player.h @@ -62,7 +62,7 @@ struct player_instance ent_gate *gate_waiting; /* - * Input + * Input TODO: move this * -------------------------------- */ struct input_binding *input_js1h, diff --git a/render.h b/render.h index 4b3828b..a80f78a 100644 --- a/render.h +++ b/render.h @@ -515,11 +515,11 @@ VG_STATIC void async_render_init( void *payload, u32 size ) } float quad[] = { - 0.00f,0.00f, 1.00f,1.00f, 0.00f,1.00f, - 0.00f,0.00f, 1.00f,0.00f, 1.00f,1.00f, + 0.00f,0.00f, 1.00f,1.00f, 0.00f,1.00f, /* fsquad */ + 0.00f,0.00f, 1.00f,0.00f, 1.00f,1.00f, - 0.20f,0.00f, 0.80f,1.00f, 0.20f,1.00f, - 0.20f,0.00f, 0.80f,0.00f, 0.80f,1.00f, + 0.00f,0.00f, 1.00f,0x1p-4f,0.00f,0x1p-4f, /* fsquad1 */ + 0.00f,0.00f, 1.00f,0.00f, 1.00f,0x1p-4f, /* 9x9 debug grid */ /* row0 */ diff --git a/skaterift.c b/skaterift.c index 73767a2..8edd117 100644 --- a/skaterift.c +++ b/skaterift.c @@ -190,6 +190,7 @@ VG_STATIC void vg_update(void) world_update( get_active_world(), localplayer.rb.co ); audio_ambient_sprites_update( get_active_world(), localplayer.rb.co ); + gui_helper_action( localplayer.input_use, "\x7f Hello \x1f""A \x1e\x84" ); } } @@ -466,6 +467,7 @@ VG_STATIC void vg_render(void) glDisable(GL_DEPTH_TEST); vg_lines_drawall(); glViewport( 0,0, vg.window_x, vg.window_y ); + gui_draw(); } VG_STATIC void vg_ui(void)