Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3694 in orxonox.OLD for orxonox/branches/textEngine/src/lib


Ignore:
Timestamp:
Mar 31, 2005, 11:45:30 AM (20 years ago)
Author:
bensch
Message:

orxonox/textEngine: doxygen tags, some minor fix

Location:
orxonox/branches/textEngine/src/lib/graphics/font
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/textEngine/src/lib/graphics/font/glfont.cc

    r3693 r3694  
    9797}
    9898
     99//! A simple variable for checking if ttf was initialized
    99100bool GLFont::ttfInitialized = false;
    100101
    101 
     102/**
     103   \brief initializes a new Font
     104   \param fontFile The file to load a Font from
     105   \param fontSize the Size in pixels of the Font
     106*/
    102107bool GLFont::init(const char* fontFile, unsigned int fontSize)
    103108{
     
    120125}
    121126
    122 
     127/**
     128   \brief sets The Font.
     129   \param fontFile The file containing the font.
     130   \returns true if loaded, false if something went wrong, or if a font was loaded before.
     131*/
    123132bool GLFont::setFont(const char* fontFile)
    124133{
     
    132141        {
    133142          PRINTF(1)("TTF_OpenFont: %s\n", TTF_GetError());
    134           // handle error
     143          return false;
    135144      }
     145      return true;
    136146    }
    137147  else
    138     PRINTF(2)("Font already initialized, unable to change it now.\n");
    139 }
    140 
    141 
     148    {
     149      PRINTF(2)("Font already initialized, unable to change it now.\n");
     150      return false;
     151    }
     152}
     153
     154/**
     155   \brief Sets a new Text to the font
     156   \param text the new text to set
     157*/
    142158void GLFont::setText(const char* text)
    143159{
     
    171187}
    172188
     189/**
     190   \brief Sets a new Size to the font
     191   \param fontSize The new Size in pixels.
     192*/
    173193void GLFont::setSize(unsigned int fontSize)
    174194{
     
    176196}
    177197
     198/**
     199   \brief sets a new color to the font
     200   \param r Red
     201   \param g Green
     202   \param b Blue
     203*/
    178204void GLFont::setColor(Uint8 r, Uint8 g, Uint8 b)
    179205{
     
    183209}
    184210
    185 
     211/**
     212   \brief sets a Position.
     213   \param x the x-position in pixels from the left border
     214   \param y the y-position in pixels from the top border
     215*/
    186216void GLFont::setPosition(int x, int y)
    187217{
     
    190220}
    191221
     222/**
     223   \brief draws the Font
     224   \todo FIX this is to slow/static
     225*/
    192226void GLFont::draw(void)
    193227{
     
    197231  glBegin(GL_QUADS);
    198232  glTexCoord2f(0, 0); glVertex2i(20,   20  );
    199   glTexCoord2f(1, 0); glVertex2i(200, 20  );
    200   glTexCoord2f(1, 1); glVertex2i(200,   80);
    201   glTexCoord2f(0, 1); glVertex2i(20, 80);
     233  glTexCoord2f(1, 0); glVertex2i(20+this->textPosSize.w, 20  );
     234  glTexCoord2f(1, 1); glVertex2i(20+this->textPosSize.w, 20+this->textPosSize.h);
     235  glTexCoord2f(0, 1); glVertex2i(20, 20+this->textPosSize.h);
    202236  glEnd();
    203237  this->leave2DMode();
     
    206240
    207241
    208 
     242/**
     243   \brief creates a texture out of the given parameters
     244*/
    209245void GLFont::createTexture(void)
    210246{
     
    213249  if (tmpSurf)
    214250    this->texture = loadTexture(tmpSurf, texcoord);
     251
     252  this->textPosSize.w = tmpSurf->w;
     253  this->textPosSize.h = tmpSurf->h;
     254  SDL_FreeSurface(tmpSurf);
    215255}
    216256
     
    261301   for more info about vertical Fonts
    262302*/
    263 glyph GLFont::getGlyphMetrics(Uint16 character)
    264 {
    265   glyph rg;
     303Glyph GLFont::getGlyphMetrics(Uint16 character)
     304{
     305  Glyph rg;
    266306  rg.character = character;
    267307  TTF_GlyphMetrics(this->font, rg.character,
     
    276316}
    277317
    278 void GLFont::renderText(void)
    279 {
    280 
    281 }
    282 
    283 
    284 
    285 void GLFont::enter2DMode()
     318/**
     319   \brief entering 2D Mode
     320   
     321   this is a GL-Projection-mode, that is orthogonal, for placing the font in fron of everything else
     322*/
     323void GLFont::enter2DMode(void)
    286324{
    287325  SDL_Surface *screen = SDL_GetVideoSurface();
     
    314352}
    315353
    316 
    317 void GLFont::leave2DMode()
     354/**
     355   \brief leaves the 2DMode again also \see GLFont::enter2DMode(void)
     356*/
     357void GLFont::leave2DMode(void)
    318358{
    319359        glMatrixMode(GL_MODELVIEW);
     
    326366}
    327367
    328 
     368/**
     369   \brief Loads a Font from an SDL_surface into a texture.
     370   \param surface The surface to make the texture of
     371   \param texcoord The texture coordinates of the 4 corners of the texture
     372   \returns the ID of the texture
     373*/
    329374GLuint GLFont::loadTexture(SDL_Surface *surface, GLfloat *texcoord)
    330375{
     
    432477
    433478
    434 /* Quick utility function for texture creation */
     479/**
     480   \brief Quick utility function for texture creation
     481   \param input an integer
     482   \returns the next bigger 2^n-integer than input
     483*/
    435484int GLFont::powerOfTwo(int input)
    436485{
     
    444493
    445494
    446 
     495/**
     496   \brief a simple function to get some interesting information about this class
     497*/
    447498void GLFont::debug(void)
    448499{
  • orxonox/branches/textEngine/src/lib/graphics/font/glfont.h

    r3693 r3694  
    1212
    1313/* some default values */
    14 #define FONT_DEFAULT_SIZE       18
    15 #define FONT_DEFAULT_TEXT       "orxonox 1234567890"
    16 #define FONT_DEFAULT_COLOR_R    256
    17 #define FONT_DEFAULT_COLOR_G    256
    18 #define FONT_DEFAULT_COLOR_B    256
    19 #define FONT_NUM_COLORS         256
     14#define FONT_DEFAULT_SIZE       50                   //!< default size of the Text
     15#define FONT_DEFAULT_TEXT       "orxonox 1234567890" //!< some default text to display
     16#define FONT_DEFAULT_COLOR_R    256                  //!< the default red part (color) of the text
     17#define FONT_DEFAULT_COLOR_G    256                  //!< the default red green (color) of the text
     18#define FONT_DEFAULT_COLOR_B    256                  //!< the default red blue (color) of the text
     19#define FONT_NUM_COLORS         256                  //!< The number of colors.
    2020
    2121
    2222
    2323//! A struct for handling glyphs
    24 struct glyph
     24/**
     25   a Glyph is one letter of a certain font
     26*/
     27struct Glyph
    2528{
    26   Uint16 character;
    27   int minX;
    28   int maxX;
    29   int minY;
    30   int maxY;
    31   int width;
    32   int height;
    33   int bearingX;
    34   int bearingY;
    35   int advance;
     29  Uint16 character;              //!< The character
     30  int minX;                      //!< The minimum distance from the origin in X
     31  int maxX;                      //!< The maximum distance from the origin in X
     32  int minY;                      //!< The minimum distance from the origin in Y
     33  int maxY;                      //!< The maximum distance from the origin in Y
     34  int width;                     //!< The width of the Glyph
     35  int height;                    //!< The height of the Glyph
     36  int bearingX;                  //!< How much is right of the Origin
     37  int bearingY;                  //!< How much is above the Origin
     38  int advance;                   //!< How big a Glyph would be in monospace-mode
    3639};
    3740
    38 
     41//! A class to handle a Font
    3942class GLFont
    4043{
     
    7174  // placement in openGL
    7275  GLuint texture;
     76  SDL_Rect textPosSize;               //!< A SDL-Rectangle representing the position and size of the Text on the screen.
    7377  int positionX;
    7478  int positionY;
     79  int width;
     80  int height;
    7581  int renderStyle;
    7682  SDL_Surface* surface;
     
    8187  int getMaxAscent(void);
    8288  int getMaxDescent(void);
    83   glyph getGlyphMetrics(Uint16 character);
     89  Glyph getGlyphMetrics(Uint16 character);
    8490
    8591  static bool ttfInitialized;
Note: See TracChangeset for help on using the changeset viewer.