Changeset 3768 in orxonox.OLD for orxonox/branches/textEngine/src/lib/graphics/font
- Timestamp:
- Apr 9, 2005, 6:45:12 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/text_engine.cc
r3767 r3768 37 37 38 38 //////////// 39 /// TEXT /// 40 //////////// 41 42 Text::Text(void) 43 { 44 45 } 46 47 Text::~Text(void) 48 { 49 50 } 51 52 53 void Text::setBindNode(PNode* bindNode) 54 { 55 this->bindNode = bindNode; 56 } 57 58 /** 59 \brief sets the Type of this Text 60 \param type the type to set. 61 */ 62 void Text::setType(int type) 63 { 64 this->type = type; 65 } 66 67 68 /** 69 \brief Sets a new Text to the font 70 \param text the new text to set 71 */ 72 void Text::setText(const char* text) 73 { 74 if (this->text) 75 delete []this->text; 76 this->text = new char[strlen(text)+1]; 77 strcpy(this->text, text); 78 } 79 80 /** 81 \brief sets a Position. 82 \param x the x-position in pixels from the left border 83 \param y the y-position in pixels from the top border 84 */ 85 void Text::setPosition(int x, int y) 86 { 87 this->posSize.x = x; 88 this->posSize.y = y; 89 } 90 91 92 /** 93 \brief draws the Font 94 \todo FIX this is to slow/static 95 */ 96 void Text::draw(void) 97 { 98 // storing all the Transformation Matrices. 99 100 GLdouble modMat[16]; 101 GLdouble projMat[16]; 102 GLint viewPort[4]; 103 glGetDoublev(GL_PROJECTION_MATRIX, projMat); 104 glGetDoublev(GL_MODELVIEW_MATRIX, modMat); 105 glGetIntegerv(GL_VIEWPORT, viewPort); 106 // this->enter2DMode(); 107 108 109 // setting the Position of this Text. 110 Vector pos; 111 if (this->bindNode) 112 { 113 GLdouble x = this->bindNode->getAbsCoor().x; 114 GLdouble y = this->bindNode->getAbsCoor().y; 115 GLdouble z = this->bindNode->getAbsCoor().z; 116 GLdouble tmp[3]; 117 gluProject(x, y, z, modMat, projMat, viewPort, tmp, tmp+1, tmp+2); 118 printf("test %f %f %f,\n", tmp[0], tmp[1], tmp[2]); 119 pos.x = tmp[0] + this->posSize.x; 120 pos.y = GraphicsEngine::getInstance()->getResolutionY() - tmp[1] + this->posSize.y; 121 pos.z = tmp[2]; 122 } 123 else 124 { 125 pos.x = this->posSize.x; 126 pos.y = this->posSize.y; 127 pos.z = 0; 128 } 129 130 // drawing this Text. 131 if(type == TEXT_STATIC) 132 { 133 glBindTexture(GL_TEXTURE_2D, this->texture); 134 glEnable(GL_TEXTURE_2D); 135 glBegin(GL_QUADS); 136 137 glTexCoord2f(this->texCoord.minU, this->texCoord.minV); 138 glVertex2i(pos.x, pos.y ); 139 140 glTexCoord2f(this->texCoord.maxU, this->texCoord.minV); 141 glVertex2i(pos.x + this->posSize.w, pos.y ); 142 143 glTexCoord2f(this->texCoord.maxU, this->texCoord.maxV); 144 glVertex2i(pos.x + this->posSize.w, pos.y + this->posSize.h); 145 146 glTexCoord2f(this->texCoord.minU, this->texCoord.maxV); 147 glVertex2i(pos.x, pos.y + this->posSize.h); 148 149 glEnd(); 150 } 151 else //(if type & TEXT_DYNAMIC) 152 { 153 Glyph** glyphArray = this->font->getGlyphArray(); 154 glBindTexture(GL_TEXTURE_2D, this->font->getFastTextureID()); 155 // glEnable(GL_TEXTURE_2D); 156 glTranslatef(pos.x, pos.y, 0); 157 158 printf("%d, %d\n", this->font->getFastTextureID(), glyphArray[65]->displayList); 159 char* tmpText = this->text; 160 while (*tmpText != '\0') 161 { 162 if(glyphArray[*tmpText]) 163 { 164 glCallList(glyphArray[*tmpText]->displayList); 165 glTranslatef(glyphArray[*tmpText]->width, 0, 0); 166 } 167 tmpText++; 168 } 169 } 170 // this->leave2DMode(); 171 } 172 173 174 175 //////////// 39 176 /// FONT /// 40 177 //////////// 41 42 178 /** 43 179 \brief constructs a Font … … 66 202 67 203 this->setSize(fontSize); 68 this->setType(TEXT_DYNAMIC); 69 70 this->currentText->renderStyle = TTF_STYLE_NORMAL; 71 204 this->setStyle(TTF_STYLE_NORMAL); 72 205 this->setFont(fontFile); 73 206 74 this->setPosition(0, 0); 75 76 this->setText(FONT_DEFAULT_TEXT); 207 208 this->currentText->setType(TEXT_DYNAMIC); 209 this->currentText->setPosition(0, 0); 210 211 this->currentText->setText(FONT_DEFAULT_TEXT); 77 212 78 213 this->setColor(r, g, b); … … 128 263 } 129 264 130 void Font::setBindNode(PNode* bindNode)131 {132 this->currentText->bindNode = bindNode;133 }134 135 /**136 \brief sets the Type of this Text137 \param type the type to set.138 */139 void Font::setType(int type)140 {141 this->currentText->type = type;142 }143 144 145 /**146 \brief Sets a new Text to the font147 \param text the new text to set148 */149 void Font::setText(const char* text)150 {151 if (this->currentText->text)152 delete []this->currentText->text;153 this->currentText->text = new char[strlen(text)+1];154 strcpy(this->currentText->text, text);155 }156 157 265 /** 158 266 \brief sets a specific renderStyle … … 162 270 void Font::setStyle(char* renderStyle) 163 271 { 164 this-> currentText->renderStyle = TTF_STYLE_NORMAL;272 this->renderStyle = TTF_STYLE_NORMAL; 165 273 166 274 for (int i = 0; i < strlen(renderStyle); i++) 167 275 if (strncmp(renderStyle+i, "b", 1) == 0) 168 this-> currentText->renderStyle |= TTF_STYLE_BOLD;276 this->renderStyle |= TTF_STYLE_BOLD; 169 277 else if (strncmp(renderStyle+i, "i", 1) == 0) 170 this-> currentText->renderStyle |= TTF_STYLE_ITALIC;278 this->renderStyle |= TTF_STYLE_ITALIC; 171 279 else if (strncmp(renderStyle+i, "u", 1) == 0) 172 this-> currentText->renderStyle |= TTF_STYLE_UNDERLINE;280 this->renderStyle |= TTF_STYLE_UNDERLINE; 173 281 174 282 if (this->font) 175 TTF_SetFontStyle(this->font, this-> currentText->renderStyle);283 TTF_SetFontStyle(this->font, this->renderStyle); 176 284 else 177 285 PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n"); 178 286 } 287 288 179 289 180 290 /** … … 198 308 this->currentText->color.g = g; 199 309 this->currentText->color.b = b; 200 }201 202 /**203 \brief sets a Position.204 \param x the x-position in pixels from the left border205 \param y the y-position in pixels from the top border206 */207 void Font::setPosition(int x, int y)208 {209 this->currentText->textPosSize.x = x;210 this->currentText->textPosSize.y = y;211 }212 213 /**214 \brief draws the Font215 \todo FIX this is to slow/static216 */217 void Font::draw(void)218 {219 // storing all the Transformation Matrices.220 GLdouble modMat[16];221 GLint viewPort[4];222 glGetDoublev(GL_PROJECTION_MATRIX, this->projMat);223 glGetDoublev(GL_MODELVIEW_MATRIX, modMat);224 glGetIntegerv(GL_VIEWPORT, viewPort);225 this->enter2DMode();226 227 // setting the Position of this Text.228 Vector pos;229 if (this->currentText->bindNode)230 {231 GLdouble x = this->currentText->bindNode->getAbsCoor().x;232 GLdouble y = this->currentText->bindNode->getAbsCoor().y;233 GLdouble z = this->currentText->bindNode->getAbsCoor().z;234 GLdouble tmp[3];235 gluProject(x, y, z, modMat, projMat, viewPort, tmp, tmp+1, tmp+2);236 printf("test %f %f %f,\n", tmp[0], tmp[1], tmp[2]);237 pos.x = tmp[0] + this->currentText->textPosSize.x;238 pos.y = GraphicsEngine::getInstance()->getResolutionY() - tmp[1] + this->currentText->textPosSize.y;239 pos.z = tmp[2];240 }241 else242 {243 pos.x = this->currentText->textPosSize.x;244 pos.y = this->currentText->textPosSize.y;245 pos.z = 0;246 }247 248 // drawing this Text.249 if(currentText->type == TEXT_STATIC)250 {251 glBindTexture(GL_TEXTURE_2D, this->currentText->texture);252 glEnable(GL_TEXTURE_2D);253 glBegin(GL_QUADS);254 255 glTexCoord2f(this->currentText->texCoord.minU, this->currentText->texCoord.minV);256 glVertex2i(pos.x, pos.y );257 258 glTexCoord2f(this->currentText->texCoord.maxU, this->currentText->texCoord.minV);259 glVertex2i(pos.x + this->currentText->textPosSize.w, pos.y );260 261 glTexCoord2f(this->currentText->texCoord.maxU, this->currentText->texCoord.maxV);262 glVertex2i(pos.x + this->currentText->textPosSize.w, pos.y + this->currentText->textPosSize.h);263 264 glTexCoord2f(this->currentText->texCoord.minU, this->currentText->texCoord.maxV);265 glVertex2i(pos.x, pos.y + this->currentText->textPosSize.h);266 267 glEnd();268 }269 else //(if currentText->type & TEXT_DYNAMIC)270 {271 glBindTexture(GL_TEXTURE_2D, this->fastTextureID);272 // glEnable(GL_TEXTURE_2D);273 glTranslatef(pos.x, pos.y, 0);274 275 printf("%d, %d\n", this->fastTextureID, glyphArray[65]->displayList);276 char* tmpText = this->currentText->text;277 while (*tmpText != '\0')278 {279 if(glyphArray[*tmpText])280 {281 glCallList(this->glyphArray[*tmpText]->displayList);282 glTranslatef(this->glyphArray[*tmpText]->width, 0, 0);283 }284 tmpText++;285 }286 }287 this->leave2DMode();288 310 } 289 311 … … 304 326 this->currentText->texture = loadTexture(tmpSurf, &this->currentText->texCoord); 305 327 306 this->currentText-> textPosSize.w = tmpSurf->w;307 this->currentText-> textPosSize.h = tmpSurf->h;328 this->currentText->posSize.w = tmpSurf->w; 329 this->currentText->posSize.h = tmpSurf->h; 308 330 SDL_FreeSurface(tmpSurf); 309 331 } … … 748 770 749 771 750 void m_inverse(const float *m, float *out) 751 { 752 float det; 753 det= m[0]*m[5]*m[10]; 754 det+= m[4]*m[9]*m[2]; 755 det+= m[8]*m[1]*m[6]; 756 det-= m[8]*m[5]*m[2]; 757 det-= m[4]*m[1]*m[10]; 758 det-= m[0]*m[9]*m[6]; 759 760 if(det!= 0.0) 761 det=1.0/det; 762 out[0]= (m[5]*m[10]-m[9]*m[6])*det; 763 out[1]= -(m[1]*m[10]-m[9]*m[2])*det; 764 out[2]= (m[1]*m[6]-m[5]*m[2])*det; 765 out[3]= 0.0; 766 out[4]= -(m[4]*m[10]-m[8]*m[6])*det; 767 out[5]= (m[0]*m[10]-m[8]*m[2])*det; 768 out[6]= -(m[0]*m[6]-m[4]*m[2])*det; 769 out[7]= 0.0; 770 out[8]= (m[4]*m[9]-m[8]*m[5])*det; 771 out[9]= -(m[0]*m[9]-m[8]*m[1])*det; 772 out[10]= (m[0]*m[5]-m[4]*m[1])*det; 773 out[11]= 0.0; 774 out[12]=- (m[12]*out[0]+m[13]*out[4]+m[14]*out[8]); 775 out[13]=- (m[12]*out[1]+m[13]*out[5]+m[14]*out[9]); 776 out[14]=- (m[12]*out[2]+m[13]*out[6]+m[14]*out[10]); 777 out[15]= 1.0; 778 } 779 780 781 Vector mvMult(const float *mat, const Vector* vec) 782 { 783 Vector tmp; 784 tmp.x = mat[0]*vec->x+mat[1]*vec->y+mat[2]*vec->z; 785 tmp.y = mat[4]*vec->x+mat[5]*vec->y+mat[6]*vec->z; 786 tmp.z = mat[8]*vec->x+mat[9]*vec->y+mat[10]*vec->z; 787 return tmp; 788 } 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 772 773 774 775 776 777 778 779 /////////////////// 780 /// TEXT-ENGINE /// 781 /////////////////// 804 782 /** 805 783 \brief standard constructor -
orxonox/branches/textEngine/src/lib/graphics/font/text_engine.h
r3767 r3768 26 26 // FORWARD DECLARATION 27 27 class PNode; 28 class Font; 28 29 template<class T> class tList; 29 30 … … 85 86 }; 86 87 88 //////////// 89 /// TEXT /// 90 //////////// 87 91 //! Represents one textElement. 88 92 class Text 89 93 { 90 94 public: 95 Text(void); 96 ~Text(void); 97 98 void setBindNode(PNode* bindNode); 99 100 void setType(int type); 101 void setText(const char* text); 102 void setPosition(int x, int y); 103 104 virtual void draw(void); 105 106 107 Font* font; 108 91 109 int type; //!< The type of this Font. 92 110 char* text; //!< The text to display … … 95 113 GLuint texture; //!< A GL-texture to hold the text 96 114 TexCoord texCoord; //!< Texture-coordinates \todo fix this to have a struct 97 SDL_Rect textPosSize; //!< An SDL-Rectangle representing the position and size of the Text on the screen. 98 int renderStyle; //!< The Renderstyle 115 SDL_Rect posSize; //!< An SDL-Rectangle representing the position and size of the Text on the screen. 99 116 100 117 PNode* bindNode; //!< A node the Text is bind to. (if NULL thr node will not be bound to anything.) 101 118 }; 102 119 103 120 //////////// 121 /// FONT /// 122 //////////// 104 123 //! A class to handle a Font of a certain ttf-File, Size and Color. 105 124 class Font … … 114 133 void setSize(unsigned int fontSize); 115 134 void setColor(Uint8 r, Uint8 g, Uint8 b); 116 117 // text118 void setBindNode(PNode* bindNode);119 void setType(int type);120 void setText(const char* text);121 135 void setStyle(char* renderStyle); 122 void setPosition(int x, int y); 136 137 inline Glyph** getGlyphArray(void) {return glyphArray;} 138 inline GLuint getFastTextureID(void) {return fastTextureID;} 123 139 void createTexture(void); 124 140 125 virtual void draw(void); 126 141 127 142 private: 128 143 // general purpose … … 133 148 char* fontFile; //!< The fontfile from whitch the font was loaded. 134 149 unsigned int fontSize; //!< The size of the font in pixels. each Font has one size. 150 int renderStyle; //!< The Renderstyle 135 151 136 152 Glyph** glyphArray; //!< An Array of all the Glyphs stored in the Array of Glyphs. … … 159 175 160 176 }; 161 162 void m_inverse(const float *m, float *out);163 Vector mvMult(const float *mat, const Vector* vec);164 177 165 178 … … 183 196 static TextEngine* singletonRef; 184 197 198 tList<Font>* fontList; 199 185 200 }; 186 201
Note: See TracChangeset
for help on using the changeset viewer.