Open Source Tomb Raider Engine
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

FontTTF.h 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*!
  2. * \file include/system/FontTTF.h
  3. * \brief TrueType Font implementation
  4. *
  5. * \author xythobuz
  6. */
  7. #ifndef _FONT_TTF_H_
  8. #define _FONT_TTF_H_
  9. #include <string>
  10. #include <vector>
  11. #include "stb/stb_truetype.h"
  12. #include "system/Shader.h"
  13. class FontMapTTF {
  14. public:
  15. FontMapTTF();
  16. FontMapTTF(FontMapTTF&& other);
  17. ~FontMapTTF();
  18. int initialize(unsigned char* fontData, int firstChar);
  19. bool contains(int c);
  20. int getTexture() { return texture; }
  21. void getQuad(int c, float* xpos, float* ypos, stbtt_aligned_quad* quad);
  22. private:
  23. int begin;
  24. int texture;
  25. stbtt_packedchar* charInfo;
  26. };
  27. class FontTTF {
  28. public:
  29. static int initialize(std::string f);
  30. static void shutdown();
  31. static unsigned int widthText(float scale, std::string s);
  32. static unsigned int heightText(float scale, unsigned int maxWidth, std::string s);
  33. static void drawText(unsigned int x, unsigned int y, float scale,
  34. glm::vec4 color, std::string s);
  35. static void drawTextWrapped(unsigned int x, unsigned int y, float scale,
  36. glm::vec4 color, unsigned int maxWidth, std::string s);
  37. private:
  38. static int charIsMapped(int c);
  39. static int getQuad(int c, float* xpos, float* ypos, stbtt_aligned_quad* quad);
  40. static void drawTextInternal(unsigned int x, unsigned int y, float scale,
  41. glm::vec4 color, unsigned int maxWidth, std::string s,
  42. bool drawWrapped);
  43. static unsigned char* fontData;
  44. static std::vector<FontMapTTF> maps;
  45. static ShaderBuffer vertexBuffer;
  46. static ShaderBuffer uvBuffer;
  47. };
  48. #endif