Changeset 4856 in orxonox.OLD for orxonox/trunk/src/lib/graphics
- Timestamp:
- Jul 14, 2005, 12:15:38 AM (19 years ago)
- Location:
- orxonox/trunk/src/lib/graphics
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/graphics/graphics_engine.cc
r4850 r4856 427 427 } 428 428 Render2D::getInstance()->tick(dt); 429 430 429 } 431 430 … … 450 449 this->geTextCFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_DYNAMIC, 0, 255, 0); 451 450 this->geTextCFPS->setAlignment(TEXT_ALIGN_LEFT); 452 this->geTextCFPS->setPosition (5, 5);451 this->geTextCFPS->setPosition2D(5, 5); 453 452 this->geTextMaxFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_DYNAMIC, 0, 255, 0); 454 453 this->geTextMaxFPS->setAlignment(TEXT_ALIGN_LEFT); 455 this->geTextMaxFPS->setPosition (5, 35);454 this->geTextMaxFPS->setPosition2D(5, 35); 456 455 this->geTextMinFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 35, TEXT_DYNAMIC, 0, 255, 0); 457 456 this->geTextMinFPS->setAlignment(TEXT_ALIGN_LEFT); 458 this->geTextMinFPS->setPosition (5, 65);457 this->geTextMinFPS->setPosition2D(5, 65); 459 458 #endif /* NO_TEXT */ 460 459 } -
orxonox/trunk/src/lib/graphics/render2D/element_2d.cc
r4847 r4856 48 48 this->setClassID(CL_ELEMENT_2D, "Element2D"); 49 49 50 this->setPosition2D(0,0); 51 this->setAlignment(E2D_ALIGN_CENTER); 52 50 53 Render2D::getInstance()->registerElement2D(this); 51 52 54 } 53 55 … … 58 60 void Element2D::positioning() 59 61 { 60 // setting the Position of this ELEM2D. 61 if (this->bindNode) 62 63 // setting the Position of this 2D-Element. 64 if (this->alignment == E2D_ALIGN_SCREEN_CENTER) 65 { 66 absPos2D.x = GraphicsEngine::getInstance()->getResolutionX()/2 + this->relPos2D[0]; 67 absPos2D.y = GraphicsEngine::getInstance()->getResolutionY()/2 + this->relPos2D[1]; 68 absPos2D.depth = 0; 69 } 70 else if (this->bindNode) 62 71 { 63 72 GLdouble projectPos[3]; -
orxonox/trunk/src/lib/graphics/render2D/element_2d.h
r4850 r4856 26 26 typedef enum 27 27 { 28 E2D_ALIGN_NONE ,29 E2D_ALIGN_LEFT ,30 E2D_ALIGN_RIGHT ,31 E2D_ALIGN_CENTER ,32 E2D_ALIGN_SCREEN_CENTER 28 E2D_ALIGN_NONE = 0, 29 E2D_ALIGN_LEFT = 1, 30 E2D_ALIGN_RIGHT = 2, 31 E2D_ALIGN_CENTER = 4, 32 E2D_ALIGN_SCREEN_CENTER = 8 33 33 } E2D_ALIGNMENT; 34 34 … … 39 39 float y; //!< The y-coordinate. 40 40 float depth; //!< The distance from the viewing plane. 41 42 41 }; 43 42 … … 49 48 virtual ~Element2D(); 50 49 51 void setPosition2D(int xCoord, int yCoord); 52 void setLayer(E2DLayer layer); 50 /** @param xCoord the xCoordinate @param yCoord the y-Coordinate. These coordinates are Relative */ 51 inline void setPosition2D(int xCoord, int yCoord) { this->relPos2D[0] = xCoord; this->relPos2D[1] = yCoord; }; 52 /** this returns the Absolute Position on the screen set by positioning in the tick-phase */ 53 inline const Position2D& getPosition2D() { return this->absPos2D; }; 54 /** @param alignment the new Alignment of the 2D-Element */ 55 inline void setAlignment(E2D_ALIGNMENT alignment) { this->alignment = alignment; }; 56 /** @param layer the Layer this is drawn on */ 57 inline void setLayer(E2DLayer layer) { this->layer = layer; }; 53 58 /** @param visible true if the Element should be visible false otherwise (will not be rendered) */ 54 59 inline void setVisibility(bool visible) { this->visible = visible; }; 55 60 /** @param bindNode the Node this 2D-element should follow. if NULL the Element will not follow anything */ 56 //inline void setBindNode(const PNode* bindNode) { this->bindNode = bindNode; };61 inline void setBindNode(const PNode* bindNode) { this->bindNode = bindNode; }; 57 62 58 63 /** @returns the visibility state */ … … 68 73 protected: 69 74 const PNode* bindNode; //!< a node over which to display this 2D-element 75 int relPos2D[2]; //!< X-coord, Y-Coord (relative to the Coordinates of the alignment if given.) 76 Position2D absPos2D; //!< The absolute position of the 2D-Element. 77 78 E2D_ALIGNMENT alignment; //!< How the Element is aligned around its Position 79 70 80 private: 71 81 bool visible; 72 int relPos2D[2]; //!< X-coord, Y-Coord (relative to the Coordinates of the alignment if given.)73 Position2D absPos2D; //!< The absolute position of the 2D-Element.74 82 E2DLayer layer; 75 83 76 E2D_ALIGNMENT alignment; //!< How the Element is aligned around its Position77 84 }; 78 85 -
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 -
orxonox/trunk/src/lib/graphics/text_engine.h
r4850 r4856 36 36 template<class T> class tList; 37 37 38 //! An enumerator for the text alignment. 39 enum TEXT_ALIGNMENT 40 { 41 TEXT_ALIGN_LEFT, 42 TEXT_ALIGN_RIGHT, 43 TEXT_ALIGN_CENTER, 44 TEXT_ALIGN_SCREEN_CENTER 45 }; 38 #define TEXT_ALIGN_LEFT E2D_ALIGN_LEFT 39 #define TEXT_ALIGN_RIGHT E2D_ALIGN_RIGHT 40 #define TEXT_ALIGN_CENTER E2D_ALIGN_CENTER 41 #define TEXT_ALIGN_SCREEN_CENTER E2D_ALIGN_SCREEN_CENTER 46 42 47 43 /* some default values */ … … 114 110 void setType(int type); 115 111 void setText(const char* text); 116 void setPosition(int x, int y);117 void setAlignment(TEXT_ALIGNMENT alignment);118 112 /** @param blending the blending intensity to set (between 0.0 and 1.0) */ 119 inline void setBlending(float blending) { this->blending = blending;}113 inline void setBlending(float blending) { this->blending = blending; }; 120 114 121 115 // Static Text … … 140 134 char* text; //!< The text to display 141 135 SDL_Color color; //!< The color of the font. 142 TEXT_ALIGNMENT alignment; //!< The aignment of the text.143 136 float blending; //!< The blending intensity. 144 137 … … 228 221 void flush(); 229 222 230 void draw() const;231 232 223 void debug() const; 233 224 … … 243 234 private: 244 235 // tList<Font>* fontList; 245 tList<Text>* textList; //!< a list of all texts of the textEngine236 tList<Text>* textList; //!< a list of all texts registered to the textEngine @todo this is overhead, do we need this?? 246 237 247 238 };
Note: See TracChangeset
for help on using the changeset viewer.