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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
  2. /*================================================================
  3. *
  4. * Project : Mtk
  5. * Author : Terry 'Mongoose' Hendrix II
  6. * Website : http://www.westga.edu/~stu7440/
  7. * Email : stu7440@westga.edu
  8. * Object : GLString
  9. * License : No use w/o permission (C) 2002 Mongoose
  10. * Comments: Open GL rendering font/string class
  11. *
  12. *
  13. * This file was generated using Mongoose's C++
  14. * template generator script. <stu7440@westga.edu>
  15. *
  16. *-- History ------------------------------------------------
  17. *
  18. * 2002.01.01:
  19. * Mongoose - Created
  20. ================================================================*/
  21. #ifndef __MTK_MONGOOSE_GLSTRING_H_
  22. #define __MTK_MONGOOSE_GLSTRING_H_
  23. typedef struct gl_string_s
  24. {
  25. int x;
  26. int y;
  27. int font;
  28. float scale;
  29. char *text;
  30. bool active;
  31. unsigned short int len;
  32. } gl_string_t;
  33. class GLString
  34. {
  35. public:
  36. GLString();
  37. /*------------------------------------------------------
  38. * Pre :
  39. * Post : Constructs an object of GLString
  40. *
  41. *-- History ------------------------------------------
  42. *
  43. * 2002.01.01:
  44. * Mongoose - Created
  45. ------------------------------------------------------*/
  46. ~GLString();
  47. /*------------------------------------------------------
  48. * Pre : GLString object is allocated
  49. * Post : Deconstructs an object of GLString
  50. *
  51. *-- History ------------------------------------------
  52. *
  53. * 2002.01.01:
  54. * Mongoose - Created
  55. ------------------------------------------------------*/
  56. void Init(unsigned int max_strings, unsigned int max_fonts, int *tex_map);
  57. /*------------------------------------------------------
  58. * Pre : Set max number of strings and font faces
  59. *
  60. * Pass an int array as a map of font texture ids
  61. * and it's size should be 'max_fonts' since
  62. * you need a texture per font =)
  63. *
  64. * Post :
  65. *
  66. *-- History ------------------------------------------
  67. *
  68. * 2002.01.01:
  69. * Mongoose - Created
  70. ------------------------------------------------------*/
  71. void SetChar(unsigned int string, unsigned int pos, char c);
  72. /*------------------------------------------------------
  73. * Pre : String is valid gl_string id
  74. * Pos is position in that gl_string to set
  75. * to character C
  76. *
  77. * Post : Sets a single byte in a string
  78. *
  79. *-- History ------------------------------------------
  80. *
  81. * 2002.03.30:
  82. * Mongoose - Created
  83. ------------------------------------------------------*/
  84. unsigned int GetStringLen(unsigned int string);
  85. /*------------------------------------------------------
  86. * Pre : String is valid gl_string id
  87. *
  88. * Post : Gets num bytes in string buffer
  89. *
  90. *-- History ------------------------------------------
  91. *
  92. * 2002.03.30:
  93. * Mongoose - Created
  94. ------------------------------------------------------*/
  95. char *GetBuffer(unsigned int string);
  96. /*------------------------------------------------------
  97. * Pre : String is valid gl_string id
  98. *
  99. * Post : Returns a pointer to string buffer
  100. *
  101. *-- History ------------------------------------------
  102. *
  103. * 2002.03.30:
  104. * Mongoose - Created
  105. ------------------------------------------------------*/
  106. void setActive(unsigned int string, bool active);
  107. void SetString(unsigned int string, const char *s, ...);
  108. /*------------------------------------------------------
  109. * Pre : String is valid gl_string id
  110. * Args form the string to fill String buffer
  111. * Args are same as printf format
  112. *
  113. * Post : Sets text in a string, which will be
  114. * truncated as needed to fit
  115. *
  116. *-- History ------------------------------------------
  117. *
  118. * 2002.03.30:
  119. * Mongoose - Created
  120. ------------------------------------------------------*/
  121. void Scale(float scale);
  122. /*------------------------------------------------------
  123. * Pre : scale is > 0.0
  124. * Post : Sets default text scaling
  125. *
  126. *-- History ------------------------------------------
  127. *
  128. * 2002.01.03:
  129. * Mongoose - Created
  130. ------------------------------------------------------*/
  131. int BuildFontList(int index);
  132. /*------------------------------------------------------
  133. * Pre : Index is valid index into the font base list
  134. * Post : Adds a new font face to font list
  135. *
  136. * Returns index of font on no error
  137. * Returns -1 on full font list
  138. *
  139. *-- History ------------------------------------------
  140. *
  141. * 2002.01.01:
  142. * Mongoose - Created
  143. ------------------------------------------------------*/
  144. int glPrintf(int x, int y, int font, const char *string, ...);
  145. /*------------------------------------------------------
  146. * Pre : X, Y are valid screen coor
  147. * Font is valid font index
  148. * String is valid string with args
  149. *
  150. * Returns 0 on no error
  151. * Returns -1 on invalid string
  152. * Returns -2 on full string list
  153. * Returns -3 on full font list
  154. *
  155. * Post : Generates a new string
  156. * Renders string to gl target
  157. *
  158. *-- History ------------------------------------------
  159. *
  160. * 2001.12.31:
  161. * Mongoose - Created
  162. ------------------------------------------------------*/
  163. void Render(int width, int height);
  164. /*------------------------------------------------------
  165. * Pre : Width and Height for the GL context
  166. * Called after scene is rendered
  167. *
  168. * GL Culling disabled
  169. *
  170. * Post : Renders strings over GL scene
  171. *
  172. *-- History ------------------------------------------
  173. *
  174. * 2002.01.01:
  175. * Mongoose - Created
  176. ------------------------------------------------------*/
  177. gl_string_t *GetString(unsigned int id);
  178. /*------------------------------------------------------
  179. * Pre : Id is valid string id
  180. * Post : Return string with id, or NULL if DNE
  181. *
  182. *-- History ------------------------------------------
  183. *
  184. * 2002.01.04:
  185. * Mongoose - Created
  186. ------------------------------------------------------*/
  187. #ifdef __TEST__
  188. int _RegressionTest(int argc, char *argv[]);
  189. /*------------------------------------------------------
  190. * Pre : argc and argv are valid
  191. * Post : Tests GLString
  192. *
  193. * Returns 0 on sucess, or an error id
  194. *
  195. *-- History ------------------------------------------
  196. *
  197. * 2002.01.01:
  198. * Mongoose - Created
  199. ------------------------------------------------------*/
  200. #endif
  201. private:
  202. unsigned int _num_string_max; /* Max number of strings buffered */
  203. unsigned int _num_font_max; /* Max number of font faces */
  204. unsigned int _num_font; /* Current number of font faces */
  205. unsigned int _num_string; /* Current number of strings buffered */
  206. int *_font_texture; /* Font texture mapping to actual
  207. texture index */
  208. int *_font_base; /* Font GL list, base index list */
  209. gl_string_t *_string; /* Buffered strings and their
  210. properities */
  211. float _scale; /* Default scale factor for new strings */
  212. };
  213. #endif