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 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. float scale; //!< Scale factor
  17. char *text; //!< Text buffer
  18. bool active; //!< active state
  19. unsigned short int len; //!< length
  20. } gl_string_t;
  21. /*!
  22. * \brief Open GL rendering font/string class
  23. */
  24. class GLString {
  25. public:
  26. /*!
  27. * \brief Constructs an object of GLString
  28. */
  29. GLString();
  30. /*!
  31. * \brief Deconstructs an object of GLString
  32. */
  33. ~GLString();
  34. /*!
  35. * \brief Set max number of strings
  36. * \param max_strings maximum number of strings
  37. */
  38. void Init(unsigned int max_strings);
  39. /*!
  40. * \brief Sets a single byte in a string
  41. * \param string valid gl string id
  42. * \param pos position in that gl string to set
  43. * \param c character to set in gl string
  44. */
  45. void SetChar(unsigned int string, unsigned int pos, char c);
  46. /*!
  47. * \brief Gets number of bytes in a string buffer
  48. * \param string valid gl string id
  49. * \returns length/number of bytes of string
  50. */
  51. unsigned int GetStringLen(unsigned int string);
  52. /*!
  53. * \brief Returns string buffer
  54. * \param string valid gl string id
  55. * \returns pointer to string buffer
  56. */
  57. char *GetBuffer(unsigned int string);
  58. void setActive(unsigned int string, bool active);
  59. /*!
  60. * \brief Sets text in a string.
  61. * It will be truncated as needed to fit
  62. * \param string valid string id
  63. * \param s format string and args like for printf
  64. */
  65. void SetString(unsigned int string, const char *s, ...);
  66. /*!
  67. * \brief Sets default text scaling
  68. * \param scale new scale factor > 0.0
  69. */
  70. void Scale(float scale);
  71. /*!
  72. * \brief Generates a new string and renders it to the gl target
  73. * \param x valid X screen coordinate
  74. * \param y valid Y screen coordinate
  75. * \param string valid format string with args like for printf
  76. * \returns 0 on success, -1 on invalid string, -2 on full string list
  77. */
  78. int glPrintf(int x, int y, const char *string, ...);
  79. /*!
  80. * \brief Renders strings over GL scene.
  81. * Should be called after scene is rendered.
  82. * GL Culling should be disabled.
  83. */
  84. void Render();
  85. /*!
  86. * \brief Get the String data structure for a string id
  87. * \param id valid string id
  88. * \returns string for id, or NULL if it does not exist
  89. */
  90. gl_string_t *GetString(unsigned int id);
  91. private:
  92. unsigned int _num_string_max; //!< Max number of strings buffered
  93. unsigned int _num_string; //!< Current number of strings buffered
  94. gl_string_t *_string; //!< Buffered strings and their properities
  95. float _scale; //!< Default scale factor for new strings
  96. };
  97. #endif