Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3767 in orxonox.OLD for orxonox/branches


Ignore:
Timestamp:
Apr 9, 2005, 4:52:22 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/textEngine: some reimplementation

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

    r3766 r3767  
    1717   !! IMPORTANT !! When using ttf fonts clear the license issues prior to
    1818   adding them to orxonox. This is really important, because we do not
    19    want to defend anyone.
     19   want to offend anyone.
    2020*/
    2121
     
    4343   \brief constructs a Font
    4444   \param fontFile the File to load the font from
    45 */
    46 Font::Font(const char* fontFile)
    47 {
    48   this->init(fontFile);
    49 }
    50 
    51 /**
    52    \brief destructs a font
    53 */
    54 Font::~Font(void)
    55 {
    56   delete this->currentText;
    57 
    58   if (this->glyphArray)
    59     {
    60       for (int i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++)
    61         delete this->glyphArray[i];
    62       delete []this->glyphArray;
    63     }
    64 
    65   if (this->font)
    66     TTF_CloseFont(this->font);
    67 }
    68 
    69 /**
    70    \brief initializes a new Font
    71    \param fontFile The file to load a Font from
    72    \param fontSize the Size in pixels of the Font
    73 */
    74 bool Font::init(const char* fontFile, unsigned int fontSize)
    75 {
    76   if (!TTF_WasInit())
     45   \param fontSize the Size of the Font in Pixels
     46   \param r Red value of the Font.
     47   \param g Green value of the Font.
     48   \param b Blue value of the Font.
     49*/
     50Font::Font(const char* fontFile, unsigned int fontSize, Uint8 r, Uint8 g, Uint8 b)
     51{
     52   if (!TTF_WasInit())
    7753    TextEngine::enableFonts();
    7854
     
    9672  this->setFont(fontFile);
    9773
    98   this->setColor(0, 255, 0);
    9974  this->setPosition(0, 0);
    10075
    10176  this->setText(FONT_DEFAULT_TEXT);
    10277 
    103   this->setColor(0,255,0);
     78  this->setColor(r, g, b);
    10479
    10580  this->createTexture();
    10681
    10782  this->fastTextureID = this->createFastTexture();
     83}
     84
     85/**
     86   \brief destructs a font
     87*/
     88Font::~Font(void)
     89{
     90  delete this->currentText;
     91
     92  if (this->glyphArray)
     93    {
     94      for (int i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++)
     95        delete this->glyphArray[i];
     96      delete []this->glyphArray;
     97    }
     98
     99  if (this->font)
     100    TTF_CloseFont(this->font);
    108101}
    109102
  • orxonox/branches/textEngine/src/lib/graphics/font/text_engine.h

    r3766 r3767  
    88
    99    for more information see the specific classes.
     10
     11    !! IMPORTANT !! When using ttf fonts clear the license issues prior to
     12   adding them to orxonox. This is really important, because we do not want
     13   to offend anyone.
    1014*/
    1115
     
    2832#define FONT_DEFAULT_SIZE       50                   //!< default size of the Text
    2933#define FONT_DEFAULT_TEXT       "orxonox 1234567890" //!< some default text to display
    30 #define FONT_DEFAULT_COLOR_R    256                  //!< the default red part (color) of the text
    31 #define FONT_DEFAULT_COLOR_G    256                  //!< the default red green (color) of the text
    32 #define FONT_DEFAULT_COLOR_B    256                  //!< the default red blue (color) of the text
     34#define FONT_DEFAULT_COLOR_R    255                  //!< the default red part (color) of the text
     35#define FONT_DEFAULT_COLOR_G    255                  //!< the default red green (color) of the text
     36#define FONT_DEFAULT_COLOR_B    255                  //!< the default red blue (color) of the text
    3337#define FONT_NUM_COLORS         256                  //!< The number of colors.
    3438
     
    7781 
    7882  // OpenGL-specific
    79   //  TexCoord texCoord;             //!< A Texture Coordinate for this glyph.
     83  //  TexCoord texCoord;         //!< A Texture Coordinate for this glyph.
    8084  GLuint displayList;            //!< DiplayList to render this Glyph.
    8185};
    8286
    83 //! A class to handle a Font
     87//! Represents one textElement.
     88class Text
     89{
     90 public:
     91  int type;                      //!< The type of this Font.
     92  char* text;                    //!< The text to display
     93  SDL_Color color;               //!< The color of the font.
     94  // placement in openGL
     95  GLuint texture;                //!< A GL-texture to hold the text
     96  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
     99 
     100  PNode* bindNode;               //!< A node the Text is bind to. (if NULL thr node will not be bound to anything.)
     101};
     102
     103
     104//! A class to handle a Font of a certain ttf-File, Size and Color.
    84105class Font
    85106{
    86107 public:
    87   Font(const char* fontFile);
     108  Font(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE,
     109       Uint8 r = FONT_DEFAULT_COLOR_R, Uint8 g = FONT_DEFAULT_COLOR_G, Uint8 b = FONT_DEFAULT_COLOR_B);
    88110  virtual ~Font();
    89111
     
    115137  GLuint fastTextureID;             //!< The fast textureID.
    116138
    117   //! Represents one textElement.
    118   struct Text
    119   {
    120     int type;                   //!< The type of this Font.
    121     char* text;                      //!< The text to display
    122     SDL_Color color;                 //!< The color of the font.
    123     // placement in openGL
    124     GLuint texture;                  //!< A GL-texture to hold the text
    125     TexCoord texCoord;               //!< Texture-coordinates \todo fix this to have a struct
    126     SDL_Rect textPosSize;            //!< An SDL-Rectangle representing the position and size of the Text on the screen.
    127     int renderStyle;                 //!< The Renderstyle
    128 
    129     PNode* bindNode;                 //!< A node the Text is bind to. (if NULL thr node will not be bound to anything.)
    130   };
    131139  tList<Text>* textList;
    132140  Text* currentText;
    133141
    134   bool init(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE);
    135142  int getMaxHeight(void);
    136143  int getMaxAscent(void);
Note: See TracChangeset for help on using the changeset viewer.