Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

GLString.h 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*!
  2. * \file include/GLString.h
  3. * \brief Open GL rendering font/string class
  4. *
  5. * \author Mongoose
  6. * \author xythobuz
  7. */
  8. #ifndef _GLSTRING_H_
  9. #define _GLSTRING_H_
  10. /*!
  11. * \brief Internal data structure representing GL Strings
  12. */
  13. typedef struct gl_string_s {
  14. int x; //!< X Coordinate
  15. int y; //!< Y Coordinate
  16. int font; //!< Font ID
  17. float scale; //!< Scale factor
  18. char *text; //!< Text buffer
  19. bool active; //!< active state
  20. unsigned short int len; //!< length
  21. } gl_string_t;
  22. /*!
  23. * \brief Open GL rendering font/string class
  24. */
  25. class GLString {
  26. public:
  27. /*!
  28. * \brief Constructs an object of GLString
  29. */
  30. GLString();
  31. /*!
  32. * \brief Deconstructs an object of GLString
  33. */
  34. ~GLString();
  35. /*!
  36. * \brief Set max number of strings and font faces
  37. * \param max_strings maximum number of strings
  38. * \param max_fonts maximum number of fonts and length of tex_map
  39. * \param tex_map int array as a map of font texture ids
  40. */
  41. void Init(unsigned int max_strings, unsigned int max_fonts, int *tex_map);
  42. /*!
  43. * \brief Sets a single byte in a string
  44. * \param string valid gl string id
  45. * \param pos position in that gl string to set
  46. * \param c character to set in gl string
  47. */
  48. void SetChar(unsigned int string, unsigned int pos, char c);
  49. /*!
  50. * \brief Gets number of bytes in a string buffer
  51. * \param string valid gl string id
  52. * \returns length/number of bytes of string
  53. */
  54. unsigned int GetStringLen(unsigned int string);
  55. /*!
  56. * \brief Returns string buffer
  57. * \param string valid gl string id
  58. * \returns pointer to string buffer
  59. */
  60. char *GetBuffer(unsigned int string);
  61. void setActive(unsigned int string, bool active);
  62. /*!
  63. * \brief Sets text in a string.
  64. * It will be truncated as needed to fit
  65. * \param string valid string id
  66. * \param s format string and args like for printf
  67. */
  68. void SetString(unsigned int string, const char *s, ...);
  69. /*!
  70. * \brief Sets default text scaling
  71. * \param scale new scale factor > 0.0
  72. */
  73. void Scale(float scale);
  74. /*!
  75. * \brief Adds a new font face to font list
  76. * \param index valid index into the font base list
  77. * \returns index of font on no error, -1 on full font list
  78. */
  79. int BuildFontList(int index);
  80. /*!
  81. * \brief Generates a new string and renders it to the gl target
  82. * \param x valid X screen coordinate
  83. * \param y valid Y screen coordinate
  84. * \param font valid font index
  85. * \param string valid format string with args like for printf
  86. * \returns 0 on success, -1 on invalid string, -2 on full string list, -3 on full font list
  87. */
  88. int glPrintf(int x, int y, int font, const char *string, ...);
  89. /*!
  90. * \brief Renders strings over GL scene.
  91. * Should be called after scene is rendered.
  92. * GL Culling should be disabled.
  93. * \param width width of GL context
  94. * \param height height of GL context
  95. */
  96. void Render(int width, int height);
  97. /*!
  98. * \brief Get the String data structure for a string id
  99. * \param id valid string id
  100. * \returns string for id, or NULL if it does not exist
  101. */
  102. gl_string_t *GetString(unsigned int id);
  103. private:
  104. unsigned int _num_string_max; //!< Max number of strings buffered
  105. unsigned int _num_font_max; //!< Max number of font faces
  106. unsigned int _num_font; //!< Current number of font faces
  107. unsigned int _num_string; //!< Current number of strings buffered
  108. int *_font_texture; //!< Font texture mapping to actual texture index
  109. int *_font_base; //!< Font GL list, base index list
  110. gl_string_t *_string; //!< Buffered strings and their properities
  111. float _scale; //!< Default scale factor for new strings
  112. };
  113. #endif