Changeset 4458 in orxonox.OLD for orxonox/trunk/src
- Timestamp:
- Jun 1, 2005, 11:51:44 PM (19 years ago)
- Location:
- orxonox/trunk/src/lib/graphics
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/graphics/graphics_engine.cc
r4374 r4458 165 165 } 166 166 167 /** 168 \brief sets Fullscreen mode 169 \param fullscreen true if fullscreen, false if windowed 170 */ 167 171 void GraphicsEngine::setFullscreen(bool fullscreen) 168 172 { … … 171 175 } 172 176 177 /** 178 \brief sets the background color 179 \param red the red part of the background 180 \param blue the blue part of the background 181 \param green the green part of the background 182 \param alpha the alpha part of the background 183 */ 173 184 void GraphicsEngine::setBackgroundColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) 174 185 { … … 290 301 } 291 302 292 303 /** 304 \brief ticks the Text 305 \param dt the time passed 306 */ 293 307 void GraphicsEngine::tick(float dt) 294 308 { 295 296 297 309 if( unlikely(this->bDisplayFPS)) 310 { 311 this->currentFPS = 1.0/dt; 298 312 if( unlikely(this->currentFPS > this->maxFPS)) this->maxFPS = this->currentFPS; 299 if( unlikely(this->currentFPS < this->minFPS)) this->minFPS = this->currentFPS; 300 301 char tmpChar1[20]; 302 sprintf(tmpChar1, "Current: %4.0f", this->currentFPS); 303 this->geTextCFPS->setText(tmpChar1); 304 char tmpChar2[20]; 305 sprintf(tmpChar2, "Max: %4.0f", this->maxFPS); 306 this->geTextMaxFPS->setText(tmpChar2); 307 char tmpChar3[20]; 308 sprintf(tmpChar3, "Min: %4.0f", this->minFPS); 309 this->geTextMinFPS->setText(tmpChar3); 310 } 311 } 312 313 if( unlikely(this->currentFPS < this->minFPS)) this->minFPS = this->currentFPS; 314 315 char tmpChar1[20]; 316 sprintf(tmpChar1, "Current: %4.0f", this->currentFPS); 317 this->geTextCFPS->setText(tmpChar1); 318 char tmpChar2[20]; 319 sprintf(tmpChar2, "Max: %4.0f", this->maxFPS); 320 this->geTextMaxFPS->setText(tmpChar2); 321 char tmpChar3[20]; 322 sprintf(tmpChar3, "Min: %4.0f", this->minFPS); 323 this->geTextMinFPS->setText(tmpChar3); 324 } 325 } 326 327 /** 328 \brief displays the Frames per second 329 \param display if the text should be displayed 330 331 \todo this is dangerous 332 */ 313 333 void GraphicsEngine::displayFPS(bool display) 314 334 { 315 316 317 318 319 320 321 322 323 324 325 326 327 328 } 329 330 335 if( display) 336 { 337 this->geTextCFPS = TextEngine::getInstance()->createText("fonts/druid.ttf", 35, TEXT_DYNAMIC, 0, 255, 0); 338 this->geTextCFPS->setAlignment(TEXT_ALIGN_LEFT); 339 this->geTextCFPS->setPosition(5, 500); 340 this->geTextMaxFPS = TextEngine::getInstance()->createText("fonts/druid.ttf", 35, TEXT_DYNAMIC, 0, 255, 0); 341 this->geTextMaxFPS->setAlignment(TEXT_ALIGN_LEFT); 342 this->geTextMaxFPS->setPosition(5, 530); 343 this->geTextMinFPS = TextEngine::getInstance()->createText("fonts/druid.ttf", 35, TEXT_DYNAMIC, 0, 255, 0); 344 this->geTextMinFPS->setAlignment(TEXT_ALIGN_LEFT); 345 this->geTextMinFPS->setPosition(5, 560); 346 } 347 this->bDisplayFPS = display; 348 } 349 350 -
orxonox/trunk/src/lib/graphics/graphics_engine.h
r4381 r4458 18 18 class Text; 19 19 20 20 //! class to handle graphics 21 /** 22 handles graphical SDL-initialisation, textures, resolutions, and so on 23 */ 21 24 class GraphicsEngine : public BaseObject 22 25 { … … 32 35 33 36 /** \returns the x resolution */ 34 inline int getResolutionX(void) {return this->resolutionX;}37 inline int getResolutionX(void) const {return this->resolutionX;} 35 38 /** \returns the y resolution */ 36 inline int getResolutionY(void) {return this->resolutionY;}39 inline int getResolutionY(void) const {return this->resolutionY;} 37 40 /** \returns the Bits Per Pixel */ 38 inline int getbbp(void) {return this->bitsPerPixel;}41 inline int getbbp(void) const {return this->bitsPerPixel;} 39 42 int resolutionChanged(SDL_ResizeEvent* resizeInfo); 40 43 void listModes(void); … … 58 61 static GraphicsEngine* singletonRef; 59 62 63 private: 64 SDL_Surface* screen; //!< the screen we draw to 65 int resolutionX; //!< the X-resoultion of the screen 66 int resolutionY; //!< the Y-resolution of the screen 67 int bitsPerPixel; //!< the bits per pixels of the screen 68 bool fullscreen; //!< if we are in fullscreen mode 69 Uint32 videoFlags; //!< flags for video 70 SDL_Rect** videoModes; //!< list of resolutions 71 72 bool bDisplayFPS; //!< is true if the fps should be displayed 73 float currentFPS; //!< the current frame rate: frames per seconds 74 float maxFPS; //!< maximal frame rate we ever got since start of the game 75 float minFPS; //!< minimal frame rate we ever got since start 60 76 61 SDL_Surface* screen; 62 int resolutionX; 63 int resolutionY; 64 int bitsPerPixel; 65 bool fullscreen; 66 Uint32 videoFlags; 67 68 bool bDisplayFPS; //!< is true if the fps should be displayed 69 float currentFPS; //!< the current frame rate: frames per seconds 70 float maxFPS; //!< maximal frame rate we ever got since start of the game 71 float minFPS; //!< minimal frame rate we ever got since start 77 Text* geTextCFPS; //!< Text for the current FPS 78 Text* geTextMaxFPS; //!< Text for the max FPS 79 Text* geTextMinFPS; //!< Text for the min FPS 72 80 73 Text* geTextCFPS;74 Text* geTextMaxFPS;75 Text* geTextMinFPS;76 77 SDL_Rect **videoModes;78 81 }; 79 82 -
orxonox/trunk/src/lib/graphics/text_engine.cc
r4320 r4458 76 76 } 77 77 78 78 /** 79 \brief tells the Text, that it should folow a PNode 80 \param bindNode: the node to bind this text to 81 */ 79 82 void Text::setBindNode(PNode* bindNode) 80 83 { … … 277 280 278 281 //////////// 282 /// UTIL /// 283 //////////// 284 /** 285 \brief Loads a Font from an SDL_surface into a texture. 286 \param surface The surface to make the texture of 287 \param texCoord The texture coordinates of the 4 corners of the texture 288 \returns the ID of the texture 289 */ 290 GLuint Text::loadTexture(SDL_Surface *surface, TexCoord* texCoord) 291 { 292 GLuint texture; 293 int w, h; 294 SDL_Surface *image; 295 SDL_Rect area; 296 Uint32 saved_flags; 297 Uint8 saved_alpha; 298 299 /* Use the surface width and height expanded to powers of 2 */ 300 w = powerOfTwo(surface->w); 301 h = powerOfTwo(surface->h); 302 if (texCoord) 303 { 304 texCoord->minU = 0.0f; 305 texCoord->minV = 0.0f; 306 texCoord->maxU = (GLfloat)surface->w / w; 307 texCoord->maxV = (GLfloat)surface->h / h; 308 } 309 image = SDL_CreateRGBSurface(SDL_SWSURFACE, 310 w, h, 311 32, 312 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ 313 0x000000FF, 314 0x0000FF00, 315 0x00FF0000, 316 0xFF000000 317 #else 318 0xFF000000, 319 0x00FF0000, 320 0x0000FF00, 321 0x000000FF 322 #endif 323 ); 324 if ( image == NULL ) { 325 return 0; 326 } 327 328 /* Save the alpha blending attributes */ 329 saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK); 330 saved_alpha = surface->format->alpha; 331 if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { 332 SDL_SetAlpha(surface, 0, 0); 333 } 334 335 /* Copy the surface into the GL texture image */ 336 area.x = 0; 337 area.y = 0; 338 area.w = surface->w; 339 area.h = surface->h; 340 SDL_BlitSurface(surface, &area, image, &area); 341 342 /* Restore the alpha blending attributes */ 343 if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { 344 SDL_SetAlpha(surface, saved_flags, saved_alpha); 345 } 346 347 /* Create an OpenGL texture for the image */ 348 glGenTextures(1, &texture); 349 glBindTexture(GL_TEXTURE_2D, texture); 350 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 351 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 352 glTexImage2D(GL_TEXTURE_2D, 353 0, 354 GL_RGBA, 355 w, h, 356 0, 357 GL_RGBA, 358 GL_UNSIGNED_BYTE, 359 image->pixels); 360 SDL_FreeSurface(image); /* No longer needed */ 361 362 return texture; 363 } 364 365 /** 366 \brief Quick utility function for texture creation 367 \param input an integer 368 \returns the next bigger 2^n-integer than input 369 */ 370 int Text::powerOfTwo(int input) 371 { 372 int value = 1; 373 374 while ( value < input ) { 375 value <<= 1; 376 } 377 return value; 378 } 379 380 381 //////////// 279 382 /// FONT /// 280 383 //////////// … … 358 461 i: italic, b: bold, u, underline 359 462 */ 360 void Font::setStyle(c har* renderStyle)463 void Font::setStyle(const char* renderStyle) 361 464 { 362 465 this->renderStyle = TTF_STYLE_NORMAL; … … 690 793 } 691 794 692 ////////////693 /// UTIL ///694 ////////////695 /**696 \brief Loads a Font from an SDL_surface into a texture.697 \param surface The surface to make the texture of698 \param texCoord The texture coordinates of the 4 corners of the texture699 \returns the ID of the texture700 */701 GLuint loadTexture(SDL_Surface *surface, TexCoord* texCoord)702 {703 GLuint texture;704 int w, h;705 SDL_Surface *image;706 SDL_Rect area;707 Uint32 saved_flags;708 Uint8 saved_alpha;709 710 /* Use the surface width and height expanded to powers of 2 */711 w = powerOfTwo(surface->w);712 h = powerOfTwo(surface->h);713 if (texCoord)714 {715 texCoord->minU = 0.0f;716 texCoord->minV = 0.0f;717 texCoord->maxU = (GLfloat)surface->w / w;718 texCoord->maxV = (GLfloat)surface->h / h;719 }720 image = SDL_CreateRGBSurface(SDL_SWSURFACE,721 w, h,722 32,723 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */724 0x000000FF,725 0x0000FF00,726 0x00FF0000,727 0xFF000000728 #else729 0xFF000000,730 0x00FF0000,731 0x0000FF00,732 0x000000FF733 #endif734 );735 if ( image == NULL ) {736 return 0;737 }738 739 /* Save the alpha blending attributes */740 saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);741 saved_alpha = surface->format->alpha;742 if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {743 SDL_SetAlpha(surface, 0, 0);744 }745 746 /* Copy the surface into the GL texture image */747 area.x = 0;748 area.y = 0;749 area.w = surface->w;750 area.h = surface->h;751 SDL_BlitSurface(surface, &area, image, &area);752 753 /* Restore the alpha blending attributes */754 if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {755 SDL_SetAlpha(surface, saved_flags, saved_alpha);756 }757 758 /* Create an OpenGL texture for the image */759 glGenTextures(1, &texture);760 glBindTexture(GL_TEXTURE_2D, texture);761 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);762 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);763 glTexImage2D(GL_TEXTURE_2D,764 0,765 GL_RGBA,766 w, h,767 0,768 GL_RGBA,769 GL_UNSIGNED_BYTE,770 image->pixels);771 SDL_FreeSurface(image); /* No longer needed */772 773 return texture;774 }775 776 /**777 \brief Quick utility function for texture creation778 \param input an integer779 \returns the next bigger 2^n-integer than input780 */781 int powerOfTwo(int input)782 {783 int value = 1;784 785 while ( value < input ) {786 value <<= 1;787 }788 return value;789 }790 791 792 793 794 795 795 796 796 /////////////////// … … 893 893 /** 894 894 \brief removes a Text from the List 895 \param t he text to delete895 \param text: the text to delete 896 896 897 897 this only ereases allocated memory, and removes the text -
orxonox/trunk/src/lib/graphics/text_engine.h
r3845 r4458 60 60 struct TexCoord 61 61 { 62 float minU;//!< The minimum U-Coordinate63 float maxU;//!< The maximum U-Coordinate64 float minV;//!< The minimum V-Coordinate65 float maxV;//!< The maximum V-Coordinate62 float minU; //!< The minimum U-Coordinate 63 float maxU; //!< The maximum U-Coordinate 64 float minV; //!< The minimum V-Coordinate 65 float maxV; //!< The maximum V-Coordinate 66 66 }; 67 67 … … 73 73 { 74 74 // Glyph-specific (size and so on) 75 Uint16 character;//!< The character76 int minX;//!< The minimum distance from the origin in X77 int maxX;//!< The maximum distance from the origin in X78 int minY;//!< The minimum distance from the origin in Y79 int maxY;//!< The maximum distance from the origin in Y80 int width;//!< The width of the Glyph81 int height;//!< The height of the Glyph82 int bearingX;//!< How much is right of the Origin83 int bearingY;//!< How much is above the Origin84 int advance;//!< How big a Glyph would be in monospace-mode75 Uint16 character; //!< The character 76 int minX; //!< The minimum distance from the origin in X 77 int maxX; //!< The maximum distance from the origin in X 78 int minY; //!< The minimum distance from the origin in Y 79 int maxY; //!< The maximum distance from the origin in Y 80 int width; //!< The width of the Glyph 81 int height; //!< The height of the Glyph 82 int bearingX; //!< How much is right of the Origin 83 int bearingY; //!< How much is above the Origin 84 int advance; //!< How big a Glyph would be in monospace-mode 85 85 86 86 // OpenGL-specific 87 87 // TexCoord texCoord; //!< A Texture Coordinate for this glyph. 88 GLuint displayList; 88 GLuint displayList; //!< DiplayList to render this Glyph. 89 89 }; 90 90 … … 110 110 // Static Text 111 111 void setColor(Uint8 r, Uint8 g, Uint8 b); 112 void setStyle(char* renderStyle);113 112 114 113 void createTexture(); … … 120 119 private: 121 120 Text(Font* font, int type = TEXT_DYNAMIC); 122 123 Font* font; 124 125 int type; //!< The type of this Font. 126 char* text; //!< The text to display 127 SDL_Color color; //!< The color of the font. 128 TEXT_ALIGNMENT alignment; //!< The aignment of the text. 129 float blending; //!< The blending intensity. 121 122 static GLuint loadTexture(SDL_Surface* surface, TexCoord* texCoord); 123 static int powerOfTwo(int input); 124 125 private: 126 Font* font; //!< Font of this text 127 128 int type; //!< The type of this Font. 129 char* text; //!< The text to display 130 SDL_Color color; //!< The color of the font. 131 TEXT_ALIGNMENT alignment; //!< The aignment of the text. 132 float blending; //!< The blending intensity. 133 130 134 // placement in openGL 131 GLuint texture;//!< A GL-texture to hold the text132 TexCoord texCoord;//!< Texture-coordinates \todo fix this to have a struct133 SDL_Rect posSize;//!< An SDL-Rectangle representing the position and size of the Text on the screen.134 135 PNode* bindNode;//!< A node the Text is bind to. (if NULL thr node will not be bound to anything.)135 GLuint texture; //!< A GL-texture to hold the text 136 TexCoord texCoord; //!< Texture-coordinates \todo fix this to have a struct 137 SDL_Rect posSize; //!< An SDL-Rectangle representing the position and size of the Text on the screen. 138 139 PNode* bindNode; //!< A node the Text is bind to. (if NULL thr node will not be bound to anything.) 136 140 }; 137 141 … … 143 147 { 144 148 friend class Text; 149 145 150 public: 146 Font(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE, 147 Uint8 r = FONT_DEFAULT_COLOR_R, Uint8 g = FONT_DEFAULT_COLOR_G, Uint8 b = FONT_DEFAULT_COLOR_B); 151 Font(const char* fontFile, 152 unsigned int fontSize = FONT_DEFAULT_SIZE, 153 Uint8 r = FONT_DEFAULT_COLOR_R, 154 Uint8 g = FONT_DEFAULT_COLOR_G, 155 Uint8 b = FONT_DEFAULT_COLOR_B); 156 148 157 virtual ~Font(); 149 158 … … 152 161 void setSize(unsigned int fontSize); 153 162 void setFastColor(Uint8 r, Uint8 g, Uint8 b); 154 void setStyle(char* renderStyle); 155 156 inline Glyph** getGlyphArray(void) {return glyphArray;} 157 inline GLuint getFastTextureID(void) {return fastTextureID;} 158 159 160 private: 161 // general purpose 162 GLdouble projMat[16]; //!< The Projection Matrix 163 164 // information about the Font 165 TTF_Font* font; //!< The font we use for this. 166 char* fontFile; //!< The fontfile from whitch the font was loaded. 167 unsigned int fontSize; //!< The size of the font in pixels. each Font has one size. 168 int renderStyle; //!< The Renderstyle 169 170 Glyph** glyphArray; //!< An Array of all the Glyphs stored in the Array of Glyphs. 171 GLuint fastTextureID; //!< The fast textureID. 172 SDL_Color fastColor; //!< A Color for the fast Texture. 173 174 tList<Text>* textList; 175 163 void setStyle(const char* renderStyle); 164 165 /** \returns a Pointer to the Array of Glyphs */ 166 inline Glyph** getGlyphArray(void) const {return glyphArray;} 167 /** \returns the texture to the fast-texture */ 168 inline GLuint getFastTextureID(void) const {return fastTextureID;} 169 170 private: 176 171 int getMaxHeight(void); 177 172 int getMaxAscent(void); … … 186 181 void debug(void); 187 182 188 }; 189 GLuint loadTexture(SDL_Surface* surface, TexCoord* texCoord); 190 int powerOfTwo(int input); 191 183 private: 184 // general purpose 185 GLdouble projMat[16]; //!< The Projection Matrix 186 187 // information about the Font 188 TTF_Font* font; //!< The font we use for this. 189 char* fontFile; //!< The fontfile from whitch the font was loaded. 190 unsigned int fontSize; //!< The size of the font in pixels. each Font has one size. 191 int renderStyle; //!< The Renderstyle 192 193 Glyph** glyphArray; //!< An Array of all the Glyphs stored in the Array of Glyphs. 194 GLuint fastTextureID; //!< The fast textureID. 195 SDL_Color fastColor; //!< A Color for the fast Texture. 196 197 tList<Text>* textList; //!< A list of texts this Font is mapped to. 198 }; 192 199 193 200 /////////////////// … … 224 231 static bool checkVersion(void); 225 232 226 233 private: 227 234 // tList<Font>* fontList; 228 tList<Text>* textList;235 tList<Text>* textList; //!< a list of all texts of the textEngine 229 236 230 237 };
Note: See TracChangeset
for help on using the changeset viewer.