Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8755 in orxonox.OLD


Ignore:
Timestamp:
Jun 23, 2006, 8:24:28 PM (18 years ago)
Author:
bensch
Message:

better with fonts

Location:
branches/fontdata/src/lib/graphics/text_engine
Files:
3 edited

Legend:

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

    r8754 r8755  
    1717
    1818#include "font.h"
    19 #include "text.h"
    2019
    2120#ifdef HAVE_SDL_IMAGE_H
     
    2423#include <SDL/SDL_image.h>
    2524#endif
     25
    2626#include "default_font.xpm"
    2727
     
    3333  : data(Font::defaultFontData)
    3434{
     35  printf("Font()\n");
    3536  this->init();
    3637
     
    4546  : data(Font::defaultFontData)
    4647{
     48  printf("Font(const std::string& fontFile, unsigned int renderSize)\n");
    4749  this->init();
    4850
    49 
     51  assert(data.get() != NULL);
    5052  this->data->renderSize = renderSize;
    5153  this->setStyle("c");
     
    6264  : data(Font::defaultFontData)
    6365{
     66  printf("Font(const std::string& imageFile)\n");
    6467  this->init();
    6568
     
    8790  : data(Font::defaultFontData)
    8891{
     92  printf("Font(char** xpmArray)\n");
     93
    8994  this->init();
    9095  this->setName("XPM-array-font");
     
    99104  }
    100105  else
    101     PRINTF(1)("loading from surface failed: %s\n", IMG_GetError());
     106    PRINTF(1)("Loading from XPM-array failed: %s\n", IMG_GetError());
    102107}
    103108
     
    119124  this->setClassID(CL_FONT, "Font");
    120125  if (Font::defaultFontData.get() == NULL)
    121     Font::defaultFontData = initDefaultFont();
    122 }
    123 
    124 FontDataPointer Font::defaultFontData = FontDataPointer(NULL); //initDefaultFont();
    125 
     126  {
     127     Font::initDefaultFont();
     128    this->data = Font::defaultFontData;
     129  }
     130}
     131
     132FontDataPointer Font::defaultFontData(NULL);
     133
     134/**
     135 * @brief initializes the default font
     136 */
     137void Font::initDefaultFont()
     138{
     139  // temporarily create a Font.
     140  Font::defaultFontData = FontDataPointer(new FontData);
     141  // apply the Data.
     142  printf("before: %p\n", defaultFontData.get());
     143  Font::defaultFontData = Font(font_xpm).data;
     144  printf("after: %p\n", defaultFontData.get());
     145}
    126146
    127147/**
     
    140160  {
    141161    this->createFastTexture();
    142     return (this->getTexture() != 0);
     162    if (this->getTexture() != 0)
     163      return true;
     164    else
     165    {
     166      this->data = Font::defaultFontData;
     167      return false;
     168    }
    143169  }
    144170  else
    145171  {
    146172    PRINTF(1)("TTF_OpenFont: %s\n", TTF_GetError());
     173    this->data = Font::defaultFontData;
    147174    return false;
    148175  }
     
    156183bool Font::loadFontFromSDL_Surface(SDL_Surface* surface)
    157184{
     185  if(surface == NULL)
     186    return false;
     187
    158188  this->data = FontDataPointer (new FontData());
    159189  // loading to a texture.
    160   if(surface == NULL)
     190
     191  bool hasAlpha;
     192  SDL_Surface* newSurf = Texture::prepareSurface(surface, hasAlpha);
     193  if (newSurf != NULL)
     194  {
     195    this->data->setSurface(newSurf);
     196    this->data->setAlpha(hasAlpha);
     197    this->data->setTexture(Texture::loadTexToGL(newSurf));
     198  }
     199  else
     200  {
     201    this->data = Font::defaultFontData;
    161202    return false;
    162 
    163   if (this->data->fontTTF != NULL)
    164   {
    165     TTF_CloseFont(this->data->fontTTF);
    166     this->data->fontTTF = NULL;
    167   }
    168   bool hasAlpha;
    169   SDL_Surface* newSurf = this->prepareSurface(surface, hasAlpha);
    170   if (newSurf != NULL)
    171   {
    172     this->setSurface(newSurf);
    173     this->setAlpha(hasAlpha);
    174     this->setTexture(Texture::loadTexToGL(newSurf));
    175203  }
    176204
     
    289317}
    290318
    291 /**
    292  * @brief initializes the default font
    293  */
    294 FontDataPointer Font::initDefaultFont()
    295 {
    296   Font::defaultFontData = FontDataPointer(new FontData);
    297   return Font(font_xpm).data;
    298 }
    299319
    300320/**
     
    466486//       sprintf( outName, "%s-glyphs.bmp", this->getName());
    467487//       SDL_SaveBMP(tmpSurf, outName);
    468   this->setAlpha(true);
    469   if (this->setSurface(tmpSurf))
    470     (this->setTexture(Texture::loadTexToGL(tmpSurf)));
     488  this->data->setAlpha(true);
     489  if (this->data->setSurface(tmpSurf))
     490    (this->data->setTexture(Texture::loadTexToGL(tmpSurf)));
    471491  return true;
    472492}
  • branches/fontdata/src/lib/graphics/text_engine/font.h

    r8754 r8755  
    1111#define _FONT_H
    1212
    13 #include "texture.h"
     13#include "material.h"
    1414
    1515#include "font_data.h"
     
    1717
    1818//! A class to handle a Font of a certain ttf-File/image-file, Size.
    19 class Font : public Texture
     19class Font : public BaseObject /* TODO Material it should be */
    2020{
    2121
    2222public:
    2323  Font();
    24   Font(const std::string& fontFile,
    25        unsigned int renderSize);
     24  Font(const std::string& fontFile, unsigned int renderSize);
    2625  Font(const std::string& imageFile);
    2726  Font(char** xpmArray);
     
    3130  bool operator==(const Font& font) const { return this->data == font.data; };
    3231
    33   //  font
     32
     33  /// LOADING new Fonts
    3434  bool loadFontFromTTF(const std::string& fontFile);
    3535  bool loadFontFromSDL_Surface(SDL_Surface* surface);
     
    4242  inline TTF_Font* getTTF() const { return this->data->getTTF(); };
    4343
     44  inline GLuint getTexture() const { return this->data->getTexture(); };
     45
     46
    4447  int getMaxHeight() const;
    4548  int getMaxAscent() const;
     
    4952  //inline static Font* getDefaultFont() { if (Font::defaultFont == NULL) initDefaultFont(); return Font::defaultFont; };
    5053
    51 
    52 
    5354  void createAsciiImage(const std::string& fileName, unsigned int size) const;
    5455
    5556  void debug() const ;
     57
    5658private:
    5759  void init();
     
    6062  bool createFastTexture();
    6163
    62 
    6364  void initGlyphs(Uint16 from, Uint16 count);
    6465  int findOptimalFastTextureSize();
    6566
    66 
    67   static FontDataPointer initDefaultFont();
     67  static void initDefaultFont();
    6868
    6969private:
  • branches/fontdata/src/lib/graphics/text_engine/text.cc

    r8754 r8755  
    3333
    3434  // initialize this Text
    35   this->_font = NULL;
    3635  this->_size = textSize;
    3736  this->setSizeY2D(textSize);
Note: See TracChangeset for help on using the changeset viewer.