Changeset 4856 in orxonox.OLD for orxonox/trunk/src/lib/graphics/text_engine.cc
- Timestamp:
- Jul 14, 2005, 12:15:38 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/graphics/text_engine.cc
r4850 r4856 61 61 this->blending = 1.0f; 62 62 this->setType(type); 63 this->setPosition(0, 0);64 63 65 64 this->setText(FONT_DEFAULT_TEXT); … … 120 119 121 120 /** 122 * sets a Position.123 * @param x the x-position in pixels from the left border124 * @param y the y-position in pixels from the top border125 */126 void Text::setPosition(int x, int y)127 {128 this->posSize.x = x;129 this->posSize.y = y;130 }131 132 /**133 * sets the text-alignment134 * @param alignment the alignment to set135 */136 void Text::setAlignment(TEXT_ALIGNMENT alignment)137 {138 this->alignment = alignment;139 }140 141 /**142 121 * sets a new color to the font 143 122 * @param r Red … … 180 159 void Text::draw() const 181 160 { 182 // setting the Position of this Text. 183 Vector pos; 184 if (this->alignment == TEXT_ALIGN_SCREEN_CENTER) 185 { 186 pos.x = GraphicsEngine::getInstance()->getResolutionX()/2 + this->posSize.x; 187 pos.y = GraphicsEngine::getInstance()->getResolutionY()/2 + this->posSize.y; 188 pos.z = 0; 189 } 190 else if (this->bindNode) 191 { 192 GLdouble x = this->bindNode->getAbsCoor().x; 193 GLdouble y = this->bindNode->getAbsCoor().y; 194 GLdouble z = this->bindNode->getAbsCoor().z; 195 GLdouble tmp[3]; 196 gluProject(x, y, z, GraphicsEngine::modMat, GraphicsEngine::projMat, GraphicsEngine::viewPort, tmp, tmp+1, tmp+2); 197 pos.x = tmp[0] + this->posSize.x; 198 pos.y = GraphicsEngine::getInstance()->getResolutionY() - tmp[1] + this->posSize.y; 199 pos.z = tmp[2]; 200 } 201 else 202 { 203 pos.x = this->posSize.x; 204 pos.y = this->posSize.y; 205 pos.z = 0; 206 } 207 161 printf("%s: %d %d, %f\n", this->getName(), absPos2D.x, absPos2D.y, absPos2D.depth); 162 163 glPushMatrix(); 164 // transform for alignment. 165 if (this->alignment == TEXT_ALIGN_RIGHT) 166 glTranslatef(-this->posSize.w, 0, 0); 167 else if (this->alignment == TEXT_ALIGN_CENTER || this->alignment == TEXT_ALIGN_SCREEN_CENTER) 168 glTranslatef(-this->posSize.w/2, 0, 0); 169 170 // drawing this Text. 208 171 // setting the Blending effects 209 172 glColor4f(1.0f,1.0f,1.0f, this->blending); … … 212 175 glBlendFunc(GL_SRC_ALPHA, GL_ONE); 213 176 214 glPushMatrix();215 // transform for alignment.216 if (this->alignment == TEXT_ALIGN_RIGHT)217 glTranslatef(-this->posSize.w, 0, 0);218 else if (this->alignment == TEXT_ALIGN_CENTER || this->alignment == TEXT_ALIGN_SCREEN_CENTER)219 glTranslatef(-this->posSize.w/2, 0, 0);220 221 // drawing this Text.222 177 if(type == TEXT_STATIC) 223 178 { 224 179 glBindTexture(GL_TEXTURE_2D, this->texture); 225 glEnable(GL_TEXTURE_2D);226 180 glBegin(GL_QUADS); 227 181 228 182 glTexCoord2f(this->texCoord.minU, this->texCoord.minV); 229 glVertex2f( pos.x, pos.y );183 glVertex2f(this->absPos2D.x, this->absPos2D.y ); 230 184 231 185 glTexCoord2f(this->texCoord.maxU, this->texCoord.minV); 232 glVertex2f( pos.x + this->posSize.w, pos.y );186 glVertex2f(this->absPos2D.x + this->posSize.w, this->absPos2D.y ); 233 187 234 188 glTexCoord2f(this->texCoord.maxU, this->texCoord.maxV); 235 glVertex2f( pos.x + this->posSize.w, pos.y + this->posSize.h);189 glVertex2f(this->absPos2D.x + this->posSize.w, absPos2D.y + this->posSize.h); 236 190 237 191 glTexCoord2f(this->texCoord.minU, this->texCoord.maxV); 238 glVertex2f( pos.x, pos.y + this->posSize.h);192 glVertex2f(absPos2D.x, absPos2D.y + this->posSize.h); 239 193 240 194 glEnd(); … … 245 199 glBindTexture(GL_TEXTURE_2D, this->font->getFastTextureID()); 246 200 // glEnable(GL_TEXTURE_2D); 247 glTranslatef( pos.x, pos.y, 0);201 glTranslatef(absPos2D.x, absPos2D.y, 0); 248 202 249 203 const char* tmpText = this->text; … … 906 860 907 861 /** 908 * draws all the Texts that have been initialized909 */910 void TextEngine::draw() const911 {912 // entering 3D-mode913 GraphicsEngine::enter2DMode();914 glEnable(GL_TEXTURE_2D);915 glEnable(GL_BLEND);916 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);917 918 // drawing all the texts919 tIterator<Text>* textIterator = textList->getIterator();920 Text* drawText = textIterator->nextElement();921 while( drawText != NULL)922 {923 drawText->draw();924 drawText = textIterator->nextElement();925 }926 delete textIterator;927 // retruning to the previous mode928 GraphicsEngine::leave2DMode();929 }930 931 /**932 862 * outputs some nice Debug information 933 863
Note: See TracChangeset
for help on using the changeset viewer.