Changeset 3714 in orxonox.OLD for orxonox/branches/textEngine/src/lib/graphics
- Timestamp:
- Apr 2, 2005, 11:24:45 PM (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
r3713 r3714 71 71 GLFont::~GLFont(void) 72 72 { 73 delete this->currentText; 74 73 75 if (this->font) 74 76 TTF_CloseFont(this->font); … … 82 84 if (!GLFont::ttfInitialized) 83 85 { 84 if(TTF_Init()==-1) {86 if(TTF_Init()==-1) 85 87 PRINTF(1)("TTF_Init: %s\n", TTF_GetError()); 86 exit(2); 87 } 88 88 89 GLFont::checkVersion(); 89 90 GLFont::ttfInitialized = true; … … 124 125 this->font = NULL; 125 126 this->fontFile = NULL; 126 this->text = NULL; 127 this->texture = 0; 127 128 this->currentText = new Text; 129 130 this->currentText->text = NULL; 131 this->currentText->texture = 0; 128 132 129 133 this->setSize(fontSize); 130 134 131 this-> renderStyle = TTF_STYLE_NORMAL;135 this->currentText->renderStyle = TTF_STYLE_NORMAL; 132 136 133 137 this->setFont(fontFile); … … 173 177 void GLFont::setText(const char* text) 174 178 { 175 if (this-> text)176 delete []this-> text;177 this-> text = new char[strlen(text)+1];178 strcpy(this-> text, text);179 if (this->currentText->text) 180 delete []this->currentText->text; 181 this->currentText->text = new char[strlen(text)+1]; 182 strcpy(this->currentText->text, text); 179 183 } 180 184 … … 186 190 void GLFont::setStyle(char* renderStyle) 187 191 { 188 this-> renderStyle = TTF_STYLE_NORMAL;192 this->currentText->renderStyle = TTF_STYLE_NORMAL; 189 193 190 194 for (int i = 0; i < strlen(renderStyle); i++) 191 195 if (strncmp(renderStyle+i, "b", 1) == 0) 192 this-> renderStyle |= TTF_STYLE_BOLD;196 this->currentText->renderStyle |= TTF_STYLE_BOLD; 193 197 else if (strncmp(renderStyle+i, "i", 1) == 0) 194 this-> renderStyle |= TTF_STYLE_ITALIC;198 this->currentText->renderStyle |= TTF_STYLE_ITALIC; 195 199 else if (strncmp(renderStyle+i, "u", 1) == 0) 196 this-> renderStyle |= TTF_STYLE_UNDERLINE;200 this->currentText->renderStyle |= TTF_STYLE_UNDERLINE; 197 201 198 202 if (this->font) 199 TTF_SetFontStyle(this->font, this-> renderStyle);203 TTF_SetFontStyle(this->font, this->currentText->renderStyle); 200 204 else 201 205 PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n"); … … 219 223 void GLFont::setColor(Uint8 r, Uint8 g, Uint8 b) 220 224 { 221 this->c olor.r = r;222 this->c olor.g = g;223 this->c olor.b = b;225 this->currentText->color.r = r; 226 this->currentText->color.g = g; 227 this->currentText->color.b = b; 224 228 } 225 229 … … 231 235 void GLFont::setPosition(int x, int y) 232 236 { 233 this-> textPosSize.x = x;234 this-> textPosSize.y = y;237 this->currentText->textPosSize.x = x; 238 this->currentText->textPosSize.y = y; 235 239 } 236 240 … … 242 246 { 243 247 this->enter2DMode(); 244 glBindTexture(GL_TEXTURE_2D, texture); 248 249 glBindTexture(GL_TEXTURE_2D, this->currentText->texture); 245 250 glEnable(GL_TEXTURE_2D); 246 251 glBegin(GL_QUADS); 247 glTexCoord2f(this->texCoord.minU, this->texCoord.minV); glVertex2i(20, 20 ); 248 glTexCoord2f(this->texCoord.maxU, this->texCoord.minV); glVertex2i(20+this->textPosSize.w, 20 ); 249 glTexCoord2f(this->texCoord.maxU, this->texCoord.maxV); glVertex2i(20+this->textPosSize.w, 20+this->textPosSize.h); 250 glTexCoord2f(this->texCoord.minU, this->texCoord.maxV); glVertex2i(20, 20+this->textPosSize.h); 252 253 glTexCoord2f(this->currentText->texCoord.minU, this->currentText->texCoord.minV); 254 glVertex2i(20, 20 ); 255 256 glTexCoord2f(this->currentText->texCoord.maxU, this->currentText->texCoord.minV); 257 glVertex2i(20+this->currentText->textPosSize.w, 20 ); 258 259 glTexCoord2f(this->currentText->texCoord.maxU, this->currentText->texCoord.maxV); 260 glVertex2i(20+this->currentText->textPosSize.w, 20+this->currentText->textPosSize.h); 261 262 glTexCoord2f(this->currentText->texCoord.minU, this->currentText->texCoord.maxV); 263 glVertex2i(20, 20+this->currentText->textPosSize.h); 264 251 265 glEnd(); 266 252 267 this->leave2DMode(); 253 254 } 255 268 } 256 269 257 270 /** … … 263 276 { 264 277 SDL_Surface* tmpSurf; 265 if (this->texture) 266 glDeleteTextures(1, &this->texture); 267 tmpSurf = TTF_RenderText_Blended(this->font, this->text, this->color); 278 if (this->currentText->texture) 279 glDeleteTextures(1, &this->currentText->texture); 280 tmpSurf = TTF_RenderText_Blended(this->font, 281 this->currentText->text, 282 this->currentText->color); 268 283 if (tmpSurf) 269 this-> texture = loadTexture(tmpSurf, &texCoord);270 271 this-> textPosSize.w = tmpSurf->w;272 this-> textPosSize.h = tmpSurf->h;284 this->currentText->texture = loadTexture(tmpSurf, &this->currentText->texCoord); 285 286 this->currentText->textPosSize.w = tmpSurf->w; 287 this->currentText->textPosSize.h = tmpSurf->h; 273 288 SDL_FreeSurface(tmpSurf); 274 289 } -
orxonox/branches/textEngine/src/lib/graphics/font/glfont.h
r3707 r3714 10 10 #include "SDL_ttf.h" 11 11 12 // FORWARD DECLARATION 13 template<class T> class tList; 12 14 13 15 /* some default values */ … … 74 76 TTF_Font* font; //!< The font we use for this. 75 77 char* fontFile; //!< The fontfile from whitch the font was loaded. 76 char* text; //!< The text to display 77 unsigned int fontSize; //!< The size of the font in pixels 78 SDL_Color color; //!< The color of the font. 78 unsigned int fontSize; //!< The size of the font in pixels. each Font has one size. 79 79 80 // placement in openGL 81 GLuint texture; //!< A GL-texture to hold the text 82 SDL_Rect textPosSize; //!< An SDL-Rectangle representing the position and size of the Text on the screen. 83 int renderStyle; //!< The Renderstyle 84 TexCoord texCoord; //!< Texture-coordinates \todo fix this to have a struct 80 //! Represents one textElement. 81 struct Text 82 { 83 char* text; //!< The text to display 84 SDL_Color color; //!< The color of the font. 85 // placement in openGL 86 GLuint texture; //!< A GL-texture to hold the text 87 TexCoord texCoord; //!< Texture-coordinates \todo fix this to have a struct 88 SDL_Rect textPosSize; //!< An SDL-Rectangle representing the position and size of the Text on the screen. 89 int renderStyle; //!< The Renderstyle 90 }; 91 tList<Text>* textList; 92 Text* currentText; 85 93 86 94 bool init(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE);
Note: See TracChangeset
for help on using the changeset viewer.