Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5347 in orxonox.OLD for trunk/src/lib/graphics/text_engine


Ignore:
Timestamp:
Oct 10, 2005, 3:07:04 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: building Graphics as a lib names libORXgraphics.a

Location:
trunk/src/lib/graphics/text_engine
Files:
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/text_engine/font.cc

    r5343 r5347  
    2424#include <SDL/SDL_image.h>
    2525#endif
    26 #include "font.xpm"
     26#include "default_font.xpm"
    2727
    2828#include "debug.h"
     
    3232
    3333/**
    34  * constructs a Font
     34 * constructs a Font out of a TTF-FIle
    3535 * @param fontFile the File to load the font from
    3636 * @param fontSize the Size of the Font in Pixels
     
    4141
    4242  this->setSize(fontSize);
     43  this->setStyle("c");
    4344
    4445  if (fontFile != NULL)
    4546    this->loadFont(fontFile);
    46 
    47   this->setStyle("c");//TTF_STYLE_NORMAL);
    48 
    49   this->fastTextureID = this->createFastTexture();
    50 
    51 
    52 //  this->createAsciiImage("test.bmp");
     47}
     48
     49/**
     50 * constructs a Font out of an ImageFile
     51 * @param imageFile the ImageFile to load the Font From.
     52 */
     53Font::Font(const char* imageFile)
     54{
     55  this->init();
     56  this->setName(imageFile);
     57  //  this->setSize(fontSize);
     58  SDL_Surface* image = NULL;
     59  if (imageFile != NULL)
     60    image = IMG_Load(imageFile);
     61  else
     62    return;
     63  if (image != NULL)
     64  {
     65    this->loadFontFromSDL_Surface(image);
     66    SDL_FreeSurface(image);
     67  }
     68  else
     69    PRINTF(1)("loading from surface %s failed: %s\n", imageFile, IMG_GetError());
    5370}
    5471
    5572/**
    5673 * constructs a Font
    57  * @param fontFile the File to load the font from
    58  * @param fontSize the Size of the Font in Pixels
     74 * @param xpmArray the xpm-ARRAY to load the font from
    5975 */
    6076Font::Font(char** xpmArray)
    6177{
    6278  this->init();
    63 
     79  this->setName("XPM-array-font");
    6480  //  this->setSize(fontSize);
    6581  SDL_Surface* image = NULL;
     
    7389  else
    7490    PRINTF(1)("loading from surface failed: %s\n", IMG_GetError());
    75 
    7691}
    7792
     
    91106      if (this->glyphArray[i] != NULL)
    92107      {
    93         glDeleteLists(this->glyphArray[i]->displayList, 1);
     108        if (this->glyphArray[i]->displayList != 0)
     109          glDeleteLists(this->glyphArray[i]->displayList, 1);
    94110        delete this->glyphArray[i];
    95111      }
     
    97113    delete[] this->glyphArray;
    98114  }
     115
     116  //! @todo check if we really do not need to delete the fastTextureID here.
     117//   if (this->fastTextureID != 0)
     118//     if(glIsTexture(this->fastTextureID))
     119//       glDeleteTextures(1, &this->fastTextureID);
    99120
    100121  // erease this font out of the memory.
     
    123144bool Font::loadFont(const char* fontFile)
    124145{
    125   if (!this->getName())
    126   {
    127     this->setName(fontFile);
    128 
    129     this->font = TTF_OpenFont(this->getName(), this->fontSize);
    130     if(!this->font)
    131     {
    132       PRINTF(1)("TTF_OpenFont: %s\n", TTF_GetError());
     146  // checking for existent Font.
     147  if (this->font != NULL)
     148  {
     149    TTF_CloseFont(this->font);
     150    this->font = NULL;
     151  }
     152  if (this->fastTextureID != 0)
     153  {
     154    if(glIsTexture(this->fastTextureID))
     155      glDeleteTextures(1, &this->fastTextureID);
     156    this->fastTextureID = 0;
     157  }
     158
     159  this->setName(fontFile);
     160  this->font = TTF_OpenFont(this->getName(), this->fontSize);
     161
     162  if(this->font != NULL)
     163  {
     164    this->fastTextureID = this->createFastTexture();
     165    if (this->fastTextureID != 0)
     166      return true;
     167    else
    133168      return false;
    134     }
    135     else
    136       return true;
    137169  }
    138170  else
    139171  {
    140     PRINTF(2)("Font already initialized, unable to change it now.\n");
     172    PRINTF(1)("TTF_OpenFont: %s\n", TTF_GetError());
    141173    return false;
    142174  }
     175
    143176}
    144177
     
    152185  if(surface == NULL)
    153186    return false;
     187
     188  if (this->font != NULL)
     189  {
     190    TTF_CloseFont(this->font);
     191    this->font = NULL;
     192  }
     193  if (this->fastTextureID != 0)
     194  {
     195    if(glIsTexture(this->fastTextureID))
     196      glDeleteTextures(1, &this->fastTextureID);
     197    this->fastTextureID = 0;
     198  }
     199
    154200  this->fastTextureID = Text::loadTexture(surface, NULL);
    155201
     
    195241/**
    196242 *  sets a specific renderStyle
    197  * @param renderStyle the Style to render: a char-array containing:
    198    i: italic, b: bold, u, underline
     243 * @param renderStyle the Style to render: a string (char-array) containing:
     244 *   i: italic, b: bold, u, underline
    199245 */
    200246void Font::setStyle(const char* renderStyle)
     
    212258  if (likely(this->font != NULL))
    213259    TTF_SetFontStyle(this->font, this->renderStyle);
    214   else
    215     PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n");
     260//  else
     261//    PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n");
    216262}
    217263
     
    363409{
    364410  Glyph* rg = new Glyph;
     411  rg->displayList = 0;
    365412  rg->character = character;
    366413  if (likely (this->font!= NULL))
     
    537584 * @returns the optimal size to use as the texture size
    538585
    539    @todo: this algorithm can be a lot more faster, althought it does
     586   @todo: this algorithm can be a lot faster, althought it does
    540587   not really matter within the init-context, and 128 glyphs.
    541588
     
    545592int Font::findOptimalFastTextureSize()
    546593{
     594  if (this->glyphArray == NULL)
     595    return 0;
     596
    547597  int i;
    548598  int x,y; // the counters
     
    555605  {
    556606    x = 0; y = 0;
    557     for (i = 0; i <= FONT_HIGHEST_KNOWN_CHAR; i++)
     607    for (i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++)
    558608    {
    559609      if((tmpGlyph = this->glyphArray[i]) != NULL)
  • trunk/src/lib/graphics/text_engine/font.h

    r5344 r5347  
    3131//! A struct for handling glyphs
    3232/**
    33    a Glyph is one letter of a certain font
     33 * a Glyph is one letter of a certain font
    3434 */
    3535struct Glyph
     
    5656/// FONT ///
    5757////////////
    58 //! A class to handle a Font of a certain ttf-File, Size and Color.
     58//! A class to handle a Font of a certain ttf-File/image-file, Size.
    5959class Font : public BaseObject
    6060{
     
    6464    Font(const char* fontFile,
    6565         unsigned int fontSize);
     66    Font(const char* imageFile);
    6667    Font(char** xpmArray);
    6768    virtual ~Font();
     
    102103  private:
    103104    static Font*  defaultFont;         //!< a default font, that is used, if other fonts were unable to be loaded.
    104   // information about the Font
     105    // information about the Font
    105106    TTF_Font*     font;                //!< The font we use for this.
    106107    unsigned int  fontSize;            //!< The size of the font in pixels. each Font has one size.
  • trunk/src/lib/graphics/text_engine/text_engine.cc

    r5344 r5347  
    7676    delete textIterator;
    7777  }
    78   // delete all remaining fonts (this is done in the ResourceManager)
     78  // delete all remaining fonts (There should not be Anything to do here)
    7979  tList<BaseObject>* fontList = ClassList::getList(CL_FONT);
    8080  if (fontList != NULL)
     
    127127/**
    128128 *  outputs some nice Debug information
    129 
    130    @todo there should also be something outputted about Font
    131 */
     129 *
     130 * @todo there should also be something outputted about Font
     131 */
    132132void TextEngine::debug() const
    133133{
  • trunk/src/lib/graphics/text_engine/text_engine.h

    r5344 r5347  
    11/*!
    22 * @file text_engine.h
    3   *  Definition of textEngine, the Font and the Text
    4 
    5    Text is the text outputed.
    6    Font is a class that loads a certain ttf-file with a specific height into memory
    7    TextEngine is used to manage the all the different Fonts that might be included
    8 
    9     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.
    14 */
     3 *  Definition of textEngine, the Font and the Text
     4 *
     5 * Text is the text outputed.
     6 * Font is a class that loads a certain ttf-file with a specific height into memory
     7 * TextEngine is used to manage the all the different Fonts that might be included
     8 *
     9 *   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.
     14 */
    1515
    1616#ifndef _TEXT_ENGINE_H
     
    2626class Text;
    2727
    28 ///////////////////
    29 /// TEXT-ENGINE ///
    30 ///////////////////
    31 //! A singleton Class that operates as a Handler for generating and rendering Text in 2D
     28//! A singleton Class that operates as a Handler initializing FONTS.
    3229class TextEngine : public BaseObject
    3330{
Note: See TracChangeset for help on using the changeset viewer.