font works
authorhgn <hgodden00@gmail.com>
Wed, 26 Apr 2023 17:24:51 +0000 (18:24 +0100)
committerhgn <hgodden00@gmail.com>
Wed, 26 Apr 2023 17:24:51 +0000 (18:24 +0100)
blender_export.py
ent_skateshop.c
font.h
gui.h
models_src/rs_font.mdl
player.h
render.h
skaterift.c

index 00c2de474d1d902eb914fd68d90609a8c887a256..84dc3a72b18572c0b62e698c3ed2717a6067c02c 100644 (file)
@@ -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
index adccac50c0521ada3f09c45da2c8b48dab30235f..a30fca9b5b343921375195d80423e34fd99818e4 100644 (file)
@@ -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 9b5a13b8b354aa18f8a4972f86749e86784a9192..a7826f504926038f09b7c17e7766d63fe1a47a4b 100644 (file)
--- 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 cf381afb64b194f66314ff78cf9a44f64c7691b7..1e576e62c87d0ec2185f8da340a533c4e23d4b0d 100644 (file)
--- 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; i<gui.helper_count; i++ ){
+      struct gui_helper *helper = &gui.helpers[i];
+
+      shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
+
+      float w = font3d_simple_draw( font, 1, helper->text, &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 */
index cd559713985391303eb7ca28ff9afab16aa0c69d..d1049e3258eedd142955fe956e5ff2962a729b0a 100644 (file)
Binary files a/models_src/rs_font.mdl and b/models_src/rs_font.mdl differ
index 72c26edb5d1cd8b8d0325520d67e4b600aea137f..d21212baebd6ce9f4f38c26d0442d3e593bc6041 100644 (file)
--- 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,
index 4b3828ba38a8f8f5a7bfc2ae855a019e916ff9b8..a80f78acff6048e8655d6bff56b9f9237972f2c2 100644 (file)
--- 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 */
index 73767a22ca3580898d32fda5604239f9d1933076..8edd117cebcad3929e2d1cf85a44a12d5210add4 100644 (file)
@@ -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)