Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. TextNode* Font::getTextNode(std::string s, glm::vec3 color, float font_size)
  2. {
  3.  
  4.     Mesh* textmesh =  new Mesh();
  5.     glm::vec2 current_pos(0.f);
  6.     float sizeRatio = font_size / m_defaultLineHeight;
  7.     for(char c : s){
  8.         if(c == '\n')
  9.         {
  10.             current_pos.x = 0.f; // left alignment -> TODO : be able to center or align right
  11.             current_pos.y += font_size;
  12.         }
  13.         else
  14.         {
  15.             CharInfo charInfo = m_charTable[c];
  16.             textmesh->addRectangle2D((current_pos + charInfo.offset)*sizeRatio,
  17.                                      charInfo.dim * sizeRatio,
  18.                                      charInfo.pos/m_scale,
  19.                                      charInfo.dim/m_scale);
  20.             current_pos.x += charInfo.xadvance;
  21.         }
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement