Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1.  
  2. void FontRender( RMesh *mesh, RFontMap const *font, float scale, char const *text )
  3. {
  4.     int_t len = strlen(text);
  5.     int_t vcount = len * 6;
  6.  
  7.     void *buf = gRender.temp_allocator->alloc( sizeof(font_vert_t) * vcount );
  8.     ASSERT_RETURN( NULL != buf );
  9.  
  10.     CArray verts;
  11.     verts.init( buf, sizeof(font_vert_t), vcount );
  12.    
  13.  
  14.     vector2_fl pos = vector2_fl(0.0f);
  15.     vector2_fl kerning;
  16.  
  17.     glyph_t *last_glyph = NULL;
  18.  
  19.     char const *c = text;
  20.     while (*c != NULL) {
  21.         char v = *c;
  22.  
  23.         glyph_t *glyph = FindGetGlyph( font, v );
  24.         FontGetKerning( &kerning, font, last_glyph, glyph );
  25.         pos.add( kerning * scale );
  26.  
  27.         CreateRectForGlyph( &verts, pos, scale, glyph );
  28.         pos.add( glyph->advance * scale );
  29.  
  30.         last_glyph = glyph;
  31.         ++c;
  32.     }
  33.  
  34.     MeshMapVertices( mesh, buf, vcount );
  35.     gRender.temp_allocator->free(buf);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement