Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. Font(const std::string font) //constructor
  2. :name(font)
  3. {
  4. std::string _font = "fonts/" + font + ".ttf";
  5.  
  6. FT_Library ft;
  7. FT_Init_FreeType(&ft);
  8.  
  9.  
  10. FT_Face face;
  11. if (FT_New_Face(ft, _font.c_str(), 0, &face))
  12. EXIT_ERROR(-11);
  13.  
  14. FT_Set_Pixel_Sizes(face, 0, 48);
  15.  
  16. for (unsigned int a = 1; a < 128; a++)
  17. {
  18. char c = a;
  19.  
  20. if (FT_Load_Char(face, c, FT_LOAD_RENDER))
  21. {
  22. EXIT_ERROR(-12);
  23. }
  24.  
  25.  
  26. //This just creates the FontTexture type, as I said before it works
  27. //fine,FontTexture is abstracted from BaseTexture which stores char* with
  28. //data. I also made sure that the stuff is loaded
  29. //there properly from inside FontTexture.
  30.  
  31.  
  32. FontTexture* _char = new FontTexture(
  33. //here is buffer passing
  34. face->glyph->bitmap.buffer,
  35. 0,
  36. { static_cast<float>(face->glyph->bitmap.width),
  37. static_cast<float>(face->glyph->bitmap.rows) });
  38.  
  39. _char->SetAdvance(face->glyph->advance.x);
  40. _char->SetBearing({ static_cast<float>(face->glyph->bitmap_left),
  41. static_cast<float>(face->glyph->bitmap_top )});
  42.  
  43.  
  44. //This just caches texture, so instead of loading it multiple times I can
  45. //just call "getTexture(name) store that pointer in the entitie's memory
  46. //and bind when Draw() is being called.
  47. TextureManager::getTextureManager().PrecacheTexture(std::to_string(a) + font, _char);
  48.  
  49. Characters.insert(std::pair<char, FontTexture*>(c, _char));
  50. }
  51.  
  52. FT_Done_Face(face);
  53. FT_Done_FreeType(ft);
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement