- Timestamp:
- Mar 31, 2005, 11:45:30 AM (20 years ago)
- Location:
- orxonox/branches/textEngine/src/lib/graphics/font
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/textEngine/src/lib/graphics/font/glfont.cc
r3693 r3694 97 97 } 98 98 99 //! A simple variable for checking if ttf was initialized 99 100 bool GLFont::ttfInitialized = false; 100 101 101 102 /** 103 \brief initializes a new Font 104 \param fontFile The file to load a Font from 105 \param fontSize the Size in pixels of the Font 106 */ 102 107 bool GLFont::init(const char* fontFile, unsigned int fontSize) 103 108 { … … 120 125 } 121 126 122 127 /** 128 \brief sets The Font. 129 \param fontFile The file containing the font. 130 \returns true if loaded, false if something went wrong, or if a font was loaded before. 131 */ 123 132 bool GLFont::setFont(const char* fontFile) 124 133 { … … 132 141 { 133 142 PRINTF(1)("TTF_OpenFont: %s\n", TTF_GetError()); 134 // handle error143 return false; 135 144 } 145 return true; 136 146 } 137 147 else 138 PRINTF(2)("Font already initialized, unable to change it now.\n"); 139 } 140 141 148 { 149 PRINTF(2)("Font already initialized, unable to change it now.\n"); 150 return false; 151 } 152 } 153 154 /** 155 \brief Sets a new Text to the font 156 \param text the new text to set 157 */ 142 158 void GLFont::setText(const char* text) 143 159 { … … 171 187 } 172 188 189 /** 190 \brief Sets a new Size to the font 191 \param fontSize The new Size in pixels. 192 */ 173 193 void GLFont::setSize(unsigned int fontSize) 174 194 { … … 176 196 } 177 197 198 /** 199 \brief sets a new color to the font 200 \param r Red 201 \param g Green 202 \param b Blue 203 */ 178 204 void GLFont::setColor(Uint8 r, Uint8 g, Uint8 b) 179 205 { … … 183 209 } 184 210 185 211 /** 212 \brief sets a Position. 213 \param x the x-position in pixels from the left border 214 \param y the y-position in pixels from the top border 215 */ 186 216 void GLFont::setPosition(int x, int y) 187 217 { … … 190 220 } 191 221 222 /** 223 \brief draws the Font 224 \todo FIX this is to slow/static 225 */ 192 226 void GLFont::draw(void) 193 227 { … … 197 231 glBegin(GL_QUADS); 198 232 glTexCoord2f(0, 0); glVertex2i(20, 20 ); 199 glTexCoord2f(1, 0); glVertex2i(20 0, 20 );200 glTexCoord2f(1, 1); glVertex2i(20 0, 80);201 glTexCoord2f(0, 1); glVertex2i(20, 80);233 glTexCoord2f(1, 0); glVertex2i(20+this->textPosSize.w, 20 ); 234 glTexCoord2f(1, 1); glVertex2i(20+this->textPosSize.w, 20+this->textPosSize.h); 235 glTexCoord2f(0, 1); glVertex2i(20, 20+this->textPosSize.h); 202 236 glEnd(); 203 237 this->leave2DMode(); … … 206 240 207 241 208 242 /** 243 \brief creates a texture out of the given parameters 244 */ 209 245 void GLFont::createTexture(void) 210 246 { … … 213 249 if (tmpSurf) 214 250 this->texture = loadTexture(tmpSurf, texcoord); 251 252 this->textPosSize.w = tmpSurf->w; 253 this->textPosSize.h = tmpSurf->h; 254 SDL_FreeSurface(tmpSurf); 215 255 } 216 256 … … 261 301 for more info about vertical Fonts 262 302 */ 263 glyph GLFont::getGlyphMetrics(Uint16 character)264 { 265 glyph rg;303 Glyph GLFont::getGlyphMetrics(Uint16 character) 304 { 305 Glyph rg; 266 306 rg.character = character; 267 307 TTF_GlyphMetrics(this->font, rg.character, … … 276 316 } 277 317 278 void GLFont::renderText(void) 279 { 280 281 } 282 283 284 285 void GLFont::enter2DMode() 318 /** 319 \brief entering 2D Mode 320 321 this is a GL-Projection-mode, that is orthogonal, for placing the font in fron of everything else 322 */ 323 void GLFont::enter2DMode(void) 286 324 { 287 325 SDL_Surface *screen = SDL_GetVideoSurface(); … … 314 352 } 315 353 316 317 void GLFont::leave2DMode() 354 /** 355 \brief leaves the 2DMode again also \see GLFont::enter2DMode(void) 356 */ 357 void GLFont::leave2DMode(void) 318 358 { 319 359 glMatrixMode(GL_MODELVIEW); … … 326 366 } 327 367 328 368 /** 369 \brief Loads a Font from an SDL_surface into a texture. 370 \param surface The surface to make the texture of 371 \param texcoord The texture coordinates of the 4 corners of the texture 372 \returns the ID of the texture 373 */ 329 374 GLuint GLFont::loadTexture(SDL_Surface *surface, GLfloat *texcoord) 330 375 { … … 432 477 433 478 434 /* Quick utility function for texture creation */ 479 /** 480 \brief Quick utility function for texture creation 481 \param input an integer 482 \returns the next bigger 2^n-integer than input 483 */ 435 484 int GLFont::powerOfTwo(int input) 436 485 { … … 444 493 445 494 446 495 /** 496 \brief a simple function to get some interesting information about this class 497 */ 447 498 void GLFont::debug(void) 448 499 { -
orxonox/branches/textEngine/src/lib/graphics/font/glfont.h
r3693 r3694 12 12 13 13 /* some default values */ 14 #define FONT_DEFAULT_SIZE 1815 #define FONT_DEFAULT_TEXT "orxonox 1234567890" 16 #define FONT_DEFAULT_COLOR_R 256 17 #define FONT_DEFAULT_COLOR_G 256 18 #define FONT_DEFAULT_COLOR_B 256 19 #define FONT_NUM_COLORS 256 14 #define FONT_DEFAULT_SIZE 50 //!< default size of the Text 15 #define FONT_DEFAULT_TEXT "orxonox 1234567890" //!< some default text to display 16 #define FONT_DEFAULT_COLOR_R 256 //!< the default red part (color) of the text 17 #define FONT_DEFAULT_COLOR_G 256 //!< the default red green (color) of the text 18 #define FONT_DEFAULT_COLOR_B 256 //!< the default red blue (color) of the text 19 #define FONT_NUM_COLORS 256 //!< The number of colors. 20 20 21 21 22 22 23 23 //! A struct for handling glyphs 24 struct glyph 24 /** 25 a Glyph is one letter of a certain font 26 */ 27 struct Glyph 25 28 { 26 Uint16 character; 27 int minX; 28 int maxX; 29 int minY; 30 int maxY; 31 int width; 32 int height; 33 int bearingX; 34 int bearingY; 35 int advance; 29 Uint16 character; //!< The character 30 int minX; //!< The minimum distance from the origin in X 31 int maxX; //!< The maximum distance from the origin in X 32 int minY; //!< The minimum distance from the origin in Y 33 int maxY; //!< The maximum distance from the origin in Y 34 int width; //!< The width of the Glyph 35 int height; //!< The height of the Glyph 36 int bearingX; //!< How much is right of the Origin 37 int bearingY; //!< How much is above the Origin 38 int advance; //!< How big a Glyph would be in monospace-mode 36 39 }; 37 40 38 41 //! A class to handle a Font 39 42 class GLFont 40 43 { … … 71 74 // placement in openGL 72 75 GLuint texture; 76 SDL_Rect textPosSize; //!< A SDL-Rectangle representing the position and size of the Text on the screen. 73 77 int positionX; 74 78 int positionY; 79 int width; 80 int height; 75 81 int renderStyle; 76 82 SDL_Surface* surface; … … 81 87 int getMaxAscent(void); 82 88 int getMaxDescent(void); 83 glyph getGlyphMetrics(Uint16 character);89 Glyph getGlyphMetrics(Uint16 character); 84 90 85 91 static bool ttfInitialized;
Note: See TracChangeset
for help on using the changeset viewer.