Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7221 in orxonox.OLD for trunk/src/lib/graphics


Ignore:
Timestamp:
Mar 15, 2006, 3:10:45 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the std-branche back, it runs on windows and Linux

svn merge https://svn.orxonox.net/orxonox/branches/std . -r7202:HEAD

Location:
trunk/src/lib/graphics
Files:
34 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/effects/fog_effect.cc

    r7193 r7221  
    126126 * @param mode the mode character
    127127 */
    128 GLint FogEffect::charToFogMode(const char* mode)
     128GLint FogEffect::stringToFogMode(const std::string& mode)
    129129{
    130   if( !strcmp( "GL_LINEAR", mode))
     130  if(mode == "GL_LINEAR")
    131131    return GL_LINEAR;
    132   else if( !strcmp("GL_EXP", mode))
     132  else if(mode == "GL_EXP")
    133133    return GL_EXP;
    134   else if(!strcmp("GL_EXP2", mode) )
     134  else if(mode == "GL_EXP2" )
    135135    return GL_EXP2;
    136136  else
  • trunk/src/lib/graphics/effects/fog_effect.h

    r7107 r7221  
    2626    virtual bool deactivate();
    2727
    28     inline void setFogMode(const char* mode) { this->fogMode = this->charToFogMode(mode); }
     28    inline void setFogMode(const std::string& mode) { this->fogMode = this->stringToFogMode(mode); }
    2929    inline void setFogDensity(float density) { this->fogDensity = density; }
    3030    inline void setFogRange(float start, float end) { this->fogStart = start; this->fogEnd = end; }
     
    3333
    3434  private:
    35     GLint charToFogMode(const char* mode);
     35    GLint stringToFogMode(const std::string& mode);
    3636
    3737
  • trunk/src/lib/graphics/effects/lense_flare.cc

    r7193 r7221  
    131131 * @param mode the mode character
    132132 */
    133 GLint LenseFlare::charToFogMode(const char* mode)
     133GLint LenseFlare::stringToFogMode(const std::string& mode)
    134134{}
    135135
     
    147147 *  7th: Texture of the third burst
    148148 */
    149 void LenseFlare::addFlare(const char* textureName)
     149void LenseFlare::addFlare(const std::string& textureName)
    150150{
    151151  if( this->flares.size() > LF_MAX_FLARES)
     
    159159  bb->setSize(50, 50);
    160160  this->flares.push_back(bb);
    161   PRINTF(0)("Added a Lenseflare Billboard with texture %s\n", textureName);
     161  PRINTF(4)("Added a Lenseflare Billboard with texture %s\n", textureName.c_str());
    162162
    163163  // the first flare belongs to the light source
     
    167167    bb->setVisibility(true);
    168168  }
    169   PRINTF(0)("Finished adding\n", textureName);
     169  PRINTF(4)("Finished adding\n");
    170170}
    171171
  • trunk/src/lib/graphics/effects/lense_flare.h

    r7015 r7221  
    3939    virtual void tick(float dt);
    4040
    41     void addFlare(const char* textureName);
     41    void addFlare(const std::string& textureName);
    4242
    4343
    4444  private:
    45     GLint charToFogMode(const char* mode);
     45    GLint stringToFogMode(const std::string& mode);
    4646    void setSourceVisibility(bool visibility) ;
    4747
  • trunk/src/lib/graphics/graphics_engine.cc

    r7193 r7221  
    7878  this->screen = NULL;
    7979
    80 
    81   // Hardware
    82   this->hwRenderer = NULL;
    83   this->hwVendor = NULL;
    84   this->hwVersion = NULL;
    85   this->hwExtensions = NULL;
    86 
    8780  // initialize the Modules
    8881  TextEngine::getInstance();
     
    10396  // delete what has to be deleted here
    10497  this->displayFPS( false );
    105 
    106   delete[] this->hwRenderer;
    107   delete[] this->hwVendor;
    108   delete[] this->hwVersion;
    109   delete this->hwExtensions;
    11098
    11199  //TextEngine
     
    169157{
    170158  // looking if we are in fullscreen-mode
    171   const char* fullscreen = iniParser->getVar(CONFIG_NAME_FULLSCREEN, CONFIG_SECTION_VIDEO, "0");
    172   if (strchr(fullscreen, '1') || !strcasecmp(fullscreen, "true"))
     159  const std::string fullscreen = iniParser->getVar(CONFIG_NAME_FULLSCREEN, CONFIG_SECTION_VIDEO, "0");
     160  if (fullscreen[0] == '1' || fullscreen == "true")
    173161    this->fullscreenFlag = SDL_FULLSCREEN;
    174162
    175163  // looking if we are in fullscreen-mode
    176   const char* textures = iniParser->getVar(CONFIG_NAME_TEXTURES, CONFIG_SECTION_VIDEO_ADVANCED, "0");
    177   if (strchr(textures, '1') || !strcasecmp(textures, "true"))
    178     Texture::setTextureEnableState( true);
     164  const std::string textures = iniParser->getVar(CONFIG_NAME_TEXTURES, CONFIG_SECTION_VIDEO_ADVANCED, "0");
     165  if (textures[0] == '1' || textures == "true")
     166    Texture::setTextureEnableState(true);
    179167  else
    180168    Texture::setTextureEnableState(false);
    181169
    182170  // searching for a usefull resolution
    183   SubString resolution(iniParser->getVar(CONFIG_NAME_RESOLUTION, CONFIG_SECTION_VIDEO, "640x480"), 'x');
     171  SubString resolution(iniParser->getVar(CONFIG_NAME_RESOLUTION, CONFIG_SECTION_VIDEO, "640x480").c_str(), 'x'); ///FIXME
    184172  //resolution.debug();
    185 
    186   this->initVideo(atoi(resolution.getString(0)), atoi(resolution.getString(1)), 16);
     173  MultiType x = resolution.getString(0), y = resolution.getString(1);
     174  this->initVideo(x.getInt(), y.getInt(), 16);
    187175
    188176  //   GraphicsEffect* fe = new FogEffect(NULL);
     
    262250 * @param icon The name of the Icon on the Disc
    263251 */
    264 void GraphicsEngine::setWindowName(const char* windowName, const char* icon)
    265 {
    266   SDL_Surface* iconSurf = SDL_LoadBMP(icon);
     252void GraphicsEngine::setWindowName(const std::string& windowName, const std::string& icon)
     253{
     254  SDL_Surface* iconSurf = SDL_LoadBMP(icon.c_str());
    267255  if (iconSurf != NULL)
    268256  {
    269257    Uint32 colorkey = SDL_MapRGB(iconSurf->format, 0, 0, 0);
    270258    SDL_SetColorKey(iconSurf, SDL_SRCCOLORKEY, colorkey);
    271     SDL_WM_SetIcon(iconSurf,NULL);
     259    SDL_WM_SetIcon(iconSurf, NULL);
    272260    SDL_FreeSurface(iconSurf);
    273261  }
    274262
    275   SDL_WM_SetCaption (windowName, icon);
     263  SDL_WM_SetCaption (windowName.c_str(), icon.c_str());
    276264}
    277265
     
    312300  //  printf("%s %s %s\n %s", renderer, vendor, version, extensions);
    313301
    314   if (this->hwRenderer == NULL && renderer != NULL)
    315   {
    316     this->hwRenderer = new char[strlen(renderer)+1];
    317     strcpy(this->hwRenderer, renderer);
    318   }
    319   if (this->hwVendor == NULL && vendor != NULL)
    320   {
    321     this->hwVendor = new char[strlen(vendor)+1];
    322     strcpy(this->hwVendor, vendor);
    323   }
    324   if (this->hwVersion == NULL && version != NULL)
    325   {
    326     this->hwVersion = new char[strlen(version)+11];
    327     strcpy(this->hwVersion, version);
    328   }
    329 
    330   if (this->hwExtensions == NULL && extensions != NULL)
    331     this->hwExtensions = new SubString((char*)glGetString(GL_EXTENSIONS), " \n\t,");
     302  if (renderer != NULL)
     303  {
     304    this->hwRenderer == renderer;
     305  }
     306  if (vendor != NULL)
     307  {
     308    this->hwVendor == vendor;
     309  }
     310  if (version != NULL)
     311  {
     312    this->hwVersion == version;
     313  }
     314
     315  if (extensions != NULL)
     316    this->hwExtensions.split(extensions, " \n\t,");
    332317
    333318  PRINT(4)("Running on : vendor: %s,  renderer: %s,  version:%s\n", vendor, renderer, version);
    334319  PRINT(4)("Extensions:\n");
    335   if (this->hwExtensions != NULL)
    336     for (unsigned int i = 0; i < this->hwExtensions->getCount(); i++)
    337       PRINT(4)("%d: %s\n", i, this->hwExtensions->getString(i));
     320  for (unsigned int i = 0; i < this->hwExtensions.getCount(); i++)
     321    PRINT(4)("%d: %s\n", i, this->hwExtensions.getString(i).c_str());
    338322
    339323
     
    529513 * @return true if it is, false otherwise
    530514 */
    531 bool GraphicsEngine::hwSupportsEXT(const char* extension)
    532 {
    533   if (this->hwExtensions != NULL)
    534     for (unsigned int i = 0; i < this->hwExtensions->getCount(); i++)
    535       if (!strcmp(extension, this->hwExtensions->getString(i)))
    536         return true;
     515bool GraphicsEngine::hwSupportsEXT(const std::string& extension)
     516{
     517  for (unsigned int i = 0; i < this->hwExtensions.getCount(); i++)
     518    if ( this->hwExtensions.getString(i) == extension)
     519      return true;
    537520  return false;
    538521}
     
    587570void GraphicsEngine::draw() const
    588571{
    589 //  LightManager::getInstance()->draw();
     572  //  LightManager::getInstance()->draw();
    590573
    591574  GraphicsEngine::storeMatrices();
     
    668651  switch (event.type)
    669652  {
    670       case EV_VIDEO_RESIZE:
    671       this->resolutionChanged(event.resize);
    672       break;
    673   }
    674 }
     653  case EV_VIDEO_RESIZE:
     654    this->resolutionChanged(event.resize);
     655    break;
     656  }
     657}
  • trunk/src/lib/graphics/graphics_engine.h

    r6990 r7221  
    1414#include "sdlincl.h"
    1515#include "glincl.h"
     16#include <list>
    1617
    17 #include <list>
     18#include "substring.h"
    1819
    1920// Forward Declaration
    2021class Text;
    2122class IniParser;
    22 class SubString;
    2323class WorldEntity;
    2424class GraphicsEffect;
     
    4141    int initFromIniFile(IniParser* iniParser);
    4242
    43     void setWindowName(const char* windowName, const char* icon);
     43    void setWindowName(const std::string& windowName, const std::string& icon);
    4444
    4545    int setResolution(int width, int height, int bpp);
     
    7474
    7575    void listModes();
    76     bool hwSupportsEXT(const char* extension);
     76    bool hwSupportsEXT(const std::string& extension);
    7777
    7878    /** @brief swaps the GL_BUFFERS */
     
    116116
    117117    // HARDWARE-Settings:
    118     char*                      hwRenderer;         //!< HW-renderer-string
    119     char*                      hwVendor;           //!< HW-vendor-string
    120     char*                      hwVersion;          //!< HW-version-string
    121     SubString*                 hwExtensions;       //!< All suported Extensions.
     118    std::string                hwRenderer;         //!< HW-renderer-string
     119    std::string                hwVendor;           //!< HW-vendor-string
     120    std::string                hwVersion;          //!< HW-version-string
     121    SubString                  hwExtensions;       //!< All suported Extensions.
    122122
    123123    // FPS-related
  • trunk/src/lib/graphics/importer/height_map.cc

    r7193 r7221  
    333333}
    334334
    335 HeightMap::HeightMap(const char* height_map_name = NULL) : VertexArrayModel()
     335HeightMap::HeightMap(const std::string& height_map_name = "")
     336  : VertexArrayModel()
    336337{
    337338   this->setClassID(CL_HEIGHT_MAP, "HeightMap");
    338    heightMap =  IMG_Load(height_map_name);
     339   heightMap =  IMG_Load(height_map_name.c_str());
    339340   if(heightMap!=NULL) {
    340341
    341                  PRINTF(0)("loading Image %s\n", height_map_name);
     342     PRINTF(0)("loading Image %s\n", height_map_name.c_str());
    342343                 PRINTF(0)("width : %i\n", heightMap->w);
    343344                 PRINTF(0)("height : %i\n", heightMap->h);
     
    350351                }
    351352
    352      else       PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name);
     353                else       PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name.c_str());
    353354
    354355
     
    361362}
    362363
    363 HeightMap::HeightMap(const char* height_map_name = NULL, const char* colour_map_name = NULL) : VertexArrayModel()
     364HeightMap::HeightMap(const std::string& height_map_name = NULL, const std::string& colour_map_name = NULL)
     365  : VertexArrayModel()
    364366{
    365367this->setClassID(CL_HEIGHT_MAP, "HeightMap");
    366368
    367    heightMap =  IMG_Load(height_map_name);
     369   heightMap =  IMG_Load(height_map_name.c_str());
    368370   if(heightMap!=NULL) {
    369371
    370                  PRINTF(0)("loading Image %s\n", height_map_name);
     372     PRINTF(0)("loading Image %s\n", height_map_name.c_str());
    371373                 PRINTF(0)("width : %i\n", heightMap->w);
    372374                 PRINTF(0)("height : %i\n", heightMap->h);
     
    379381                }
    380382
    381      else       PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name);
     383                else       PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name.c_str());
    382384
    383385
     
    385387
    386388  colourMap=NULL;
    387   if(colour_map_name != NULL)
     389  if(colour_map_name != "")
    388390  {
    389   colourMap = IMG_Load(colour_map_name);
     391    colourMap = IMG_Load(colour_map_name.c_str());
    390392  }
    391393
    392394  if(colourMap != NULL)
    393395                {
    394                  PRINTF(0)("loading Image %s\n", colour_map_name);
     396                  PRINTF(0)("loading Image %s\n", colour_map_name.c_str());
    395397                 PRINTF(0)("width : %i\n", colourMap->w);
    396398                 PRINTF(0)("height : %i\n", colourMap->h);
  • trunk/src/lib/graphics/importer/height_map.h

    r6981 r7221  
    5959void load();
    6060void load(int Mode);
    61 void load(const char*, int Mode);
     61void load(const std::string&, int Mode);
    6262void scale( Vector V);
    6363void setAbsCoor(Vector V);
     
    6565float getNormal(float x, float y);
    6666HeightMap();
    67 HeightMap(const char*);
    68 HeightMap(const char*, const char*);
     67HeightMap(const std::string&);
     68HeightMap(const std::string&, const std::string&);
    6969virtual ~HeightMap();
    7070
  • trunk/src/lib/graphics/importer/material.cc

    r7193 r7221  
    3434 * @param mtlName Name of the Material to be added to the Material List
    3535 */
    36 Material::Material (const char* mtlName)
     36Material::Material (const std::string& mtlName)
    3737{
    3838  this->setClassID(CL_MATERIAL, "Material");
     
    278278 * @param pathName The Path to add.
    279279*/
    280 void Material::addTexturePath(const char* pathName)
     280void Material::addTexturePath(const std::string& pathName)
    281281{
    282282  ResourceManager::getInstance()->addImageDir(pathName);
     
    289289 * @param dMap the Name of the Image to Use
    290290*/
    291 void Material::setDiffuseMap(const char* dMap, GLenum target)
     291void Material::setDiffuseMap(const std::string& dMap, GLenum target)
    292292{
    293293  PRINTF(5)("setting Diffuse Map %s\n", dMap);
     
    297297  //! @todo check if RESOURCE MANAGER is availiable
    298298  //! @todo Textures from .mtl-file need special care.
    299   if (dMap != NULL)
     299  if (!dMap.empty())
    300300    this->diffuseTexture = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target);
    301301  else
     
    308308   @todo implement this
    309309*/
    310 void Material::setAmbientMap(const char* aMap, GLenum target)
     310void Material::setAmbientMap(const std::string& aMap, GLenum target)
    311311{
    312312  SDL_Surface* ambientMap;
     
    319319   @todo implement this
    320320*/
    321 void Material::setSpecularMap(const char* sMap, GLenum target)
     321void Material::setSpecularMap(const std::string& sMap, GLenum target)
    322322{
    323323  SDL_Surface* specularMap;
     
    330330   @todo implemet this
    331331*/
    332 void Material::setBump(const char* bump)
    333 {
    334 
    335 }
     332void Material::setBump(const std::string& bump)
     333{
     334
     335}
  • trunk/src/lib/graphics/importer/material.h

    r7057 r7221  
    2626{
    2727 public:
    28   Material (const char* mtlName = NULL);
     28  Material (const std::string& mtlName = "");
    2929  virtual ~Material ();
    3030
     
    4949
    5050 // MAPPING //
    51   void setDiffuseMap(const char* dMap, GLenum target = GL_TEXTURE_2D);
    52   void setAmbientMap(const char* aMap, GLenum target = GL_TEXTURE_2D);
    53   void setSpecularMap(const char* sMap, GLenum target = GL_TEXTURE_2D);
    54   void setBump(const char* bump);
     51  void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D);
     52  void setAmbientMap(const std::string& aMap, GLenum target = GL_TEXTURE_2D);
     53  void setSpecularMap(const std::string& sMap, GLenum target = GL_TEXTURE_2D);
     54  void setBump(const std::string& bump);
    5555  GLuint getDiffuseTexture() const { return (this->diffuseTexture)? this->diffuseTexture->getTexture() : 0; };
    5656
    57   static void addTexturePath(const char* pathName);
     57  static void addTexturePath(const std::string& pathName);
    5858
    5959  private:
  • trunk/src/lib/graphics/importer/md2Model.cc

    r7193 r7221  
    7575  \brief simple constructor initializing all variables
    7676*/
    77 MD2Model::MD2Model(const char* modelFileName, const char* skinFileName, float scale)
     77MD2Model::MD2Model(const std::string& modelFileName, const std::string& skinFileName, float scale)
    7878{
    7979  this->setClassID(CL_MD2_MODEL, "MD2Model");
    8080  /* this creates the data container via ressource manager */
    81   this->data = (MD2Data*)ResourceManager::getInstance()->load(modelFileName, MD2, RP_GAME, skinFileName, scale);
     81  if (!modelFileName.empty())
     82    this->data = (MD2Data*)ResourceManager::getInstance()->load(modelFileName, MD2, RP_GAME, skinFileName, scale);
    8283  if( unlikely(this->data == NULL))
    8384    PRINTF(0)("The model was not found, MD2Model Loader finished abnormaly. Update the data-repos\n");
     
    352353{
    353354  PRINT(0)("\n==========================| MD2Model::debug() |===\n");
    354   PRINT(0)("=  Model FileName:\t%s\n", this->data->fileName);
    355   PRINT(0)("=  Skin FileName:\t%s\n", this->data->skinFileName);
     355  PRINT(0)("=  Model FileName:\t%s\n", this->data->fileName.c_str());
     356  PRINT(0)("=  Skin FileName:\t%s\n", this->data->skinFileName.c_str());
    356357  PRINT(0)("=  Size in Memory:\t%i Bytes\n", this->data->header->frameSize * this->data->header->numFrames + 64); // 64bytes is the header size
    357358  PRINT(0)("=  Number of Vertices:\t%i\n", this->data->header->numVertices);
     
    370371  \brief simple constructor
    371372*/
    372 MD2Data::MD2Data(const char* modelFileName, const char* skinFileName, float scale)
     373MD2Data::MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale)
    373374{
    374375  scale *= 0.1f;
     
    387388  this->scaleFactor = scale;
    388389
    389   this->fileName = NULL;
    390   this->skinFileName = NULL;
     390  this->fileName = "";
     391  this->skinFileName = "";
    391392  this->loadModel(modelFileName);
    392393  this->loadSkin(skinFileName);
     
    401402MD2Data::~MD2Data()
    402403{
    403   delete [] this->fileName;
    404   delete [] this->skinFileName;
    405404  delete this->header;
    406405
     
    419418  \return true if success
    420419*/
    421 bool MD2Data::loadModel(const char* fileName)
     420bool MD2Data::loadModel(const std::string& fileName)
    422421{
    423422  FILE *pFile;                            //file stream
     
    428427
    429428  //! @todo this chek should include deleting a loaded model (eventually)
    430   if (fileName == NULL)
     429  if (fileName.empty())
    431430    return false;
    432431
    433   pFile = fopen(fileName, "rb");
     432  pFile = fopen(fileName.c_str(), "rb");
    434433  if( unlikely(!pFile))
    435434    {
     
    442441  if( unlikely(this->header->version != MD2_VERSION) && unlikely(this->header->ident != MD2_IDENT))
    443442    {
    444       PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName);
     443      PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName.c_str());
    445444      return false;
    446445    }
    447446
    448   this->fileName = new char[strlen(fileName)+1];
    449   strcpy(this->fileName, fileName);
     447  this->fileName =fileName;
    450448  /* got the data: map it to locals */
    451449  this->numFrames = this->header->numFrames;
     
    507505  \return true if success
    508506*/
    509 bool MD2Data::loadSkin(const char* fileName)
    510 {
    511   if( fileName == NULL)
    512     {
    513       this->skinFileName = NULL;
     507bool MD2Data::loadSkin(const std::string& fileName)
     508{
     509  if( fileName.empty())
     510    {
     511      this->skinFileName = "";
    514512      return false;
    515513    }
    516514
    517   this->skinFileName = new char[strlen(fileName)+1];
    518   strcpy(this->skinFileName, fileName);
     515  this->skinFileName = fileName;
    519516
    520517  this->material.setName("md2ModelMaterial");
  • trunk/src/lib/graphics/importer/md2Model.h

    r7123 r7221  
    189189{
    190190 public:
    191    MD2Data(const char* modelFileName, const char* skinFileName, float scale = 1.0f);
     191   MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f);
    192192  virtual ~MD2Data();
    193193
    194194 private:
    195   bool loadModel(const char* fileName);
    196   bool loadSkin(const char* fileName = NULL);
     195   bool loadModel(const std::string& fileName);
     196   bool loadSkin(const std::string& fileName = "");
    197197
    198198 public:
     
    202202  int                numTexCoor;            //!< number of texture coordinates
    203203  int                numGLCommands;         //!< number of gl commands in the glList (tells how to draw)
    204   char*              fileName;              //!< file name of the model File
    205   char*              skinFileName;          //!< file name of the skin file
     204  std::string        fileName;              //!< file name of the model File
     205  std::string        skinFileName;          //!< file name of the skin file
    206206  MD2Header*         header;                //!< the header file
    207207
     
    223223
    224224public:
    225   MD2Model(const char* modelFileName, const char* skinFileName = NULL, float scale = 1.0f);
     225  MD2Model(const std::string& modelFileName, const std::string& skinFileName = "", float scale = 1.0f);
    226226  virtual ~MD2Model();
    227227
  • trunk/src/lib/graphics/importer/media_container.cc

    r7193 r7221  
    3434 * Default constructor
    3535 */
    36 MediaContainer::MediaContainer(const char* filename)
     36MediaContainer::MediaContainer(const std::string& filename)
    3737{
    3838  // set the class id for the base object
     
    4141  fps = 0;
    4242  mediaLoaded = false;
    43 
    44   this->loadMedia(filename);
     43  if (!filename.empty())
     44    this->loadMedia(filename);
    4545}
    4646
     
    8484}
    8585
    86 bool MediaContainer::loadMedia(const char* filename)
     86bool MediaContainer::loadMedia(const std::string& filename)
    8787{
    8888  this->unloadMedia();
    8989
    90   if(filename == NULL)
     90  if(filename.empty())
    9191    return false;
    9292  // check whether file exists
    9393  if(!ResourceManager::isInDataDir(filename))
    9494  {
    95     PRINTF(1)("Could not find %s\n", filename);
     95    PRINTF(1)("Could not find %s\n", filename.c_str());
    9696    return false;
    9797  }
     
    101101
    102102  // Open video file
    103   if (av_open_input_file(&format_context, ResourceManager::getFullName(filename), NULL, 0, NULL) !=0 )
    104   {
    105     PRINTF(1)("Could not open %s\n", ResourceManager::getFullName(filename));
     103  if (av_open_input_file(&format_context, ResourceManager::getFullName(filename).c_str(), NULL, 0, NULL) !=0 )
     104  {
     105    PRINTF(1)("Could not open %s\n", ResourceManager::getFullName(filename).c_str());
    106106    return false;
    107107  }
     
    110110  if (av_find_stream_info(format_context) < 0)
    111111  {
    112     PRINTF(1)("Could not find stream information in %s\n", ResourceManager::getFullName(filename));
     112    PRINTF(1)("Could not find stream information in %s\n", ResourceManager::getFullName(filename).c_str());
    113113    return false;
    114114  }
     
    116116  // Find the first video stream and take it
    117117  video_stream = av_find_default_stream_index(format_context);
    118  
     118
    119119  if(video_stream == -1)
    120120  {
    121     PRINTF(1)("Could not find a video stream in %s\n", ResourceManager::getFullName(filename));
     121    PRINTF(1)("Could not find a video stream in %s\n", ResourceManager::getFullName(filename).c_str());
    122122    return false;
    123123  }
     
    202202      // Free the packet that was allocated by av_read_frame
    203203      av_free_packet(&packet);
    204      
     204
    205205      // Did we get a video frame?
    206206      if(frame_finished)
     
    216216          memcpy(&data[i*codec_context->width*3],
    217217                 ((AVPicture*)RGB_frame)->data[0]+i *
    218                  ((AVPicture*)RGB_frame)->linesize[0], 
     218                 ((AVPicture*)RGB_frame)->linesize[0],
    219219                  codec_context->width*sizeof(uint8_t)*3);
    220220
     
    258258  }
    259259  else
    260     return NULL;
    261 }
     260    return 0;
     261}
  • trunk/src/lib/graphics/importer/media_container.h

    r6981 r7221  
    4444public:
    4545
    46   MediaContainer(const char* filename = NULL);
     46  MediaContainer(const std::string& filename = "");
    4747  virtual ~MediaContainer();
    4848
    49   bool loadMedia(const char* filename);
     49  bool loadMedia(const std::string& filename);
    5050  void loadFrames();
    5151
  • trunk/src/lib/graphics/importer/movie_player.cc

    r7193 r7221  
    3131
    3232
    33 MoviePlayer::MoviePlayer(const char* filename)
     33MoviePlayer::MoviePlayer(const std::string& filename)
    3434{
    3535  // set the class id for the base object
     
    4242  mediaLoaded = false;
    4343
    44   this->loadMovie(filename);
    45 
     44  if (!filename.empty())
     45    this->loadMovie(filename);
    4646}
    4747
     
    8383
    8484
    85 bool MoviePlayer::loadMovie(const char* filename)
     85bool MoviePlayer::loadMovie(const std::string& filename)
    8686{
    8787  this->unloadMedia();
    8888
    89   if(filename == NULL)
     89  if(filename.empty())
    9090    return false;
    9191  // check whether file exists
    9292  if(!ResourceManager::isInDataDir(filename))
    9393  {
    94     PRINTF(1)("Could not find %s\n", filename);
     94    PRINTF(1)("Could not find %s\n", filename.c_str());
    9595    return false;
    9696  }
     
    100100
    101101  // Open video file
    102   if (av_open_input_file(&format_context, ResourceManager::getFullName(filename), NULL, 0, NULL) !=0 )
    103   {
    104     PRINTF(1)("Could not open %s\n", ResourceManager::getFullName(filename));
     102  if (av_open_input_file(&format_context, ResourceManager::getFullName(filename).c_str(), NULL, 0, NULL) !=0 )
     103  {
     104    PRINTF(1)("Could not open %s\n", ResourceManager::getFullName(filename).c_str());
    105105    return false;
    106106  }
     
    109109  if (av_find_stream_info(format_context) < 0)
    110110  {
    111     PRINTF(1)("Could not find stream information in %s\n", ResourceManager::getFullName(filename));
     111    PRINTF(1)("Could not find stream information in %s\n", ResourceManager::getFullName(filename).c_str());
    112112    return false;
    113113  }
     
    118118  if(video_stream == -1)
    119119  {
    120     PRINTF(1)("Could not find a video stream in %s\n", ResourceManager::getFullName(filename));
     120    PRINTF(1)("Could not find a video stream in %s\n", ResourceManager::getFullName(filename).c_str());
    121121    return false;
    122122  }
  • trunk/src/lib/graphics/importer/movie_player.h

    r6981 r7221  
    5858public:
    5959
    60   MoviePlayer(const char* filename = NULL);
     60  MoviePlayer(const std::string& filename = "");
    6161  virtual ~MoviePlayer();
    6262
    63   bool loadMovie(const char* filename);
     63  bool loadMovie(const std::string& filename);
    6464
    6565  void start(float start_time);
  • trunk/src/lib/graphics/importer/objModel.cc

    r6162 r7221  
    3232 * @param scaling The factor that the model will be scaled with.
    3333*/
    34 OBJModel::OBJModel(const char* fileName, float scaling) : StaticModel(fileName)
     34OBJModel::OBJModel(const std::string& fileName, float scaling)
     35  : StaticModel(fileName)
    3536{
    3637  this->setClassID(CL_OBJ_MODEL, "OBJModel");
     
    5152*/
    5253OBJModel::~OBJModel()
    53 {
    54   PRINTF(4)("Deleting the obj-names\n");
    55   if (this->objPath)
    56     delete []this->objPath;
    57 }
     54{ }
    5855
    5956/**
     
    6360   Splits the FileName from the DirectoryName
    6461*/
    65 bool OBJModel::importFile (const char* fileName)
    66 {
     62bool OBJModel::importFile (const std::string& fileNameInput)
     63{
     64  const char* fileName = fileNameInput.c_str();
    6765  PRINTF(4)("preparing to read in file: %s\n", fileName);
    6866  // splitting the
     
    7472    {
    7573      int len = split - fileName+1;
    76       this->objPath = new char[len +2];
    77       strncpy(this->objPath, fileName, len);
     74      this->objPath =  fileName;
     75      this->objPath.erase(len, this->objPath.size());
    7876      this->objPath[len] = '\0';
    7977      PRINTF(4)("Resolved file %s to Path %s.\n", fileName, this->objPath);
     
    9189   This function does read the file, parses it for the occurence of things like vertices, faces and so on, and executes the specific tasks
    9290*/
    93 bool OBJModel::readFromObjFile(const char* fileName)
     91bool OBJModel::readFromObjFile(const std::string& fileName)
    9492{
    9593  FILE* stream;
    96   if( (stream = fopen (fileName, "r")) == NULL)
    97     {
    98       PRINTF(2)("Object File Could not be Opened %s\n", fileName);
     94  if( (stream = fopen (fileName.c_str(), "r")) == NULL)
     95    {
     96      PRINTF(2)("Object File Could not be Opened %s\n", fileName.c_str());
    9997      return false;
    10098    }
     
    162160 * that a material does not have to be able to read itself in from a File.
    163161 */
    164 bool OBJModel::readMtlLib (const char* mtlFile)
    165 {
    166   char* fileName = new char [strlen(this->objPath) + strlen(mtlFile)+1];
    167   sprintf(fileName, "%s%s", this->objPath, mtlFile);
     162bool OBJModel::readMtlLib (const std::string& mtlFile)
     163{
     164  std::string fileName = this->objPath + mtlFile;
    168165
    169166  FILE* stream;
    170   if( (stream = fopen (fileName, "r")) == NULL)
    171     {
    172       PRINTF(2)("MaterialLibrary could not be opened %s\n", fileName);
    173       delete[] fileName;
     167  if( (stream = fopen (fileName.c_str(), "r")) == NULL)
     168    {
     169      PRINTF(2)("MaterialLibrary could not be opened %s\n", fileName.c_str());
    174170      return false;
    175171    }
     
    258254    }
    259255  fclose(stream);
    260   delete []fileName;
    261256  return true;
    262257}
  • trunk/src/lib/graphics/importer/objModel.h

    r6022 r7221  
    1313{
    1414 public:
    15   OBJModel(const char* fileName, float scaling = 1.0);
     15   OBJModel(const std::string& fileName, float scaling = 1.0);
    1616  virtual ~OBJModel();
    1717
    1818 private:
    1919  ///// readin /////
    20   bool importFile (const char* fileName);
    21   bool readFromObjFile (const char* fileName);
    22   bool readMtlLib (const char* matFile);
     20   bool importFile (const std::string& fileName);
     21   bool readFromObjFile (const std::string& fileName);
     22   bool readMtlLib (const std::string& matFile);
    2323
    2424 private:
    25   char*       objPath;     //!< The Path where the obj and mtl-file are located.
     25   std::string       objPath;     //!< The Path where the obj and mtl-file are located.
    2626};
    2727
  • trunk/src/lib/graphics/importer/static_model.cc

    r6423 r7221  
    2323#include <stdarg.h>
    2424
    25 #include "vector.h"
    26 
    2725using namespace std;
    2826
     
    8684{
    8785  PRINTF(4)("Adding new Group\n");
    88   this->name = NULL;
     86  this->name = "";
    8987  this->faceMode = -1;
    9088  this->faceCount = 0;
     
    109107  if (this->listNumber != 0)
    110108    glDeleteLists(this->listNumber, 1);
    111 
    112   if (this->name != NULL)
    113     delete[] this->name;
    114109
    115110  if (this->next !=NULL)
     
    142137 * assigns it a Name and a Type
    143138 */
    144 StaticModel::StaticModel(const char* modelName)
     139StaticModel::StaticModel(const std::string& modelName)
    145140{
    146141  this->setClassID(CL_STATIC_MODEL, "StaticModel");
     
    230225  ModelGroup* tmpGroup = this->firstGroup;
    231226  while (tmpGroup != NULL)
    232     {
    233       PRINTF(5)("Drawing model %s\n", tmpGroup->name);
    234       glCallList (tmpGroup->listNumber);
    235       tmpGroup = tmpGroup->next;
    236     }
     227  {
     228    PRINTF(5)("Drawing model %s\n", tmpGroup->name);
     229    glCallList (tmpGroup->listNumber);
     230    tmpGroup = tmpGroup->next;
     231  }
    237232}
    238233
     
    247242{
    248243  if (unlikely(groupNumber >= this->groupCount))
    249     {
    250       PRINTF(2)("You requested model number %i, but this File only contains of %i Models.\n", groupNumber-1, this->groupCount);
    251       return;
    252     }
     244  {
     245    PRINTF(2)("You requested model number %i, but this File only contains of %i Models.\n", groupNumber-1, this->groupCount);
     246    return;
     247  }
    253248  PRINTF(4)("drawing the requested 3D-Models if found.\n");
    254249  ModelGroup* tmpGroup = this->firstGroup;
    255250  int counter = 0;
    256251  while (tmpGroup != NULL)
     252  {
     253    if (counter == groupNumber)
    257254    {
    258       if (counter == groupNumber)
    259         {
    260           PRINTF(4)("Drawing model number %i named %s\n", counter, tmpGroup->name);
    261           glCallList (tmpGroup->listNumber);
    262           return;
    263         }
    264       ++counter;
    265       tmpGroup = tmpGroup->next;
     255      PRINTF(4)("Drawing model number %i named %s\n", counter, tmpGroup->name);
     256      glCallList (tmpGroup->listNumber);
     257      return;
    266258    }
     259    ++counter;
     260    tmpGroup = tmpGroup->next;
     261  }
    267262  PRINTF(2)("Model number %i in %s not Found.\n", groupNumber, this->getName());
    268263  return;
     
    276271 * It does this by just calling the List that must have been created earlier.
    277272 */
    278 void StaticModel::draw (char* groupName) const
    279 {
    280   if (groupName == NULL)
    281      return;
     273void StaticModel::draw (const std::string& groupName) const
     274{
    282275  PRINTF(4)("drawing the requested 3D-Models if found.\n");
    283276  ModelGroup* tmpGroup = this->firstGroup;
    284277  while (tmpGroup != NULL)
     278  {
     279    if (tmpGroup->name == groupName)
    285280    {
    286       if (tmpGroup->name != NULL && !strcmp(tmpGroup->name, groupName))
    287         {
    288           PRINTF(4)("Drawing model %s\n", tmpGroup->name);
    289           glCallList (tmpGroup->listNumber);
    290           return;
    291         }
    292       tmpGroup = tmpGroup->next;
     281      PRINTF(4)("Drawing model %s\n", tmpGroup->name.c_str());
     282      glCallList (tmpGroup->listNumber);
     283      return;
    293284    }
    294   PRINTF(2)("Model Named %s in %s not Found.\n", groupName, this->getName());
     285    tmpGroup = tmpGroup->next;
     286  }
     287  PRINTF(2)("Model Named %s in %s not Found.\n", groupName.c_str(), this->getName());
    295288  return;
    296289}
     
    341334 * @returns the added material
    342335 */
    343 Material* StaticModel::addMaterial(const char* materialName)
     336Material* StaticModel::addMaterial(const std::string& materialName)
    344337{
    345338  ModelMaterial* modMat = new ModelMaterial;
     
    357350 * @returns the Material if found, NULL otherwise
    358351 */
    359 Material* StaticModel::findMaterialByName(const char* materialName)
     352Material* StaticModel::findMaterialByName(const std::string& materialName)
    360353{
    361354  list<ModelMaterial*>::iterator modMat;
    362355  for  (modMat = this->materialList.begin(); modMat != this->materialList.end(); modMat++)
    363     if (!strcmp((*modMat)->material->getName(), materialName))
     356    if (materialName == (*modMat)->material->getName())
    364357      return (*modMat)->material;
    365358  return NULL;
     
    373366 * With it you should be able to create Models with more than one SubModel inside
    374367 */
    375 bool StaticModel::addGroup(const char* groupString)
     368bool StaticModel::addGroup(const std::string& groupString)
    376369{
    377370  PRINTF(5)("Read Group: %s.\n", groupString);
    378371  if (this->groupCount != 0 && this->currentGroup->faceCount > 0)
    379     {
    380       // finalizeGroup(currentGroup);
    381       this->currentGroup = this->currentGroup->next = new ModelGroup;
    382     }
     372  {
     373    // finalizeGroup(currentGroup);
     374    this->currentGroup = this->currentGroup->next = new ModelGroup;
     375  }
    383376  // setting the group name if not default.
    384   if (strcmp(groupString, "default"))
    385     {
    386       this->currentGroup->name = new char [strlen(groupString)+1];
    387       strcpy(this->currentGroup->name, groupString);
    388     }
     377  if (groupString == "default")
     378  {
     379    this->currentGroup->name = groupString;
     380  }
    389381  ++this->groupCount;
    390382}
     
    396388 *  If a vertex line is found this function will inject it into the vertex-Array
    397389 */
    398 bool StaticModel::addVertex (const char* vertexString)
     390bool StaticModel::addVertex (const std::string& vertexString)
    399391{
    400392  float subbuffer1;
    401393  float subbuffer2;
    402394  float subbuffer3;
    403   sscanf (vertexString, "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);
     395  sscanf (vertexString.c_str(), "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);
    404396  this->vertices.push_back(subbuffer1*scaleFactor);
    405397  this->vertices.push_back(subbuffer2*scaleFactor);
     
    431423 * If a vertexNormal line is found this function will inject it into the vertexNormal-Array
    432424 */
    433 bool StaticModel::addVertexNormal (const char* normalString)
     425bool StaticModel::addVertexNormal (const std::string& normalString)
    434426{
    435427  float subbuffer1;
    436428  float subbuffer2;
    437429  float subbuffer3;
    438   sscanf (normalString, "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);
     430  sscanf (normalString.c_str(), "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3);
    439431  this->normals.push_back(subbuffer1);
    440432  this->normals.push_back(subbuffer2);
     
    471463 * !! WARNING THIS IS DIFFERNT FROM addVervexTexture(float, float); because it changes the second entry to 1-v !!
    472464 */
    473 bool StaticModel::addVertexTexture (const char* vTextureString)
     465bool StaticModel::addVertexTexture (const std::string& vTextureString)
    474466{
    475467  float subbuffer1;
    476468  float subbuffer2;
    477   sscanf (vTextureString, "%f %f", &subbuffer1, &subbuffer2);
     469  sscanf (vTextureString.c_str(), "%f %f", &subbuffer1, &subbuffer2);
    478470  this->vTexture.push_back(subbuffer1);
    479471  this->vTexture.push_back(1 - subbuffer2);
     
    507499 * String is different from the argument addFace,
    508500 * in this, that the first Vertex/Normal/Texcoord is 1 instead of 0
    509  */
    510 bool StaticModel::addFace (const char* faceString)
    511 {
     501 *
     502 * @TODO make it std::string conform
     503 */
     504bool StaticModel::addFace (const std::string& faceStringInput)
     505{
     506  const char* faceString = faceStringInput.c_str();
    512507  if (this->currentGroup->faceCount >0)
    513508    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace;
     
    516511  tmpElem->next = NULL;
    517512  while(strcmp (faceString, "\0"))
     513  {
     514    if (this->currentGroup->currentFace->vertexCount>0)
     515      tmpElem = tmpElem->next = new ModelFaceElement;
     516    tmpElem->next = NULL;
     517
     518    char tmpValue [50];
     519    int tmpLen;
     520    char* vertex = NULL;
     521    char* texture = NULL;
     522    char* normal = NULL;
     523
     524    sscanf (faceString, "%s", tmpValue);
     525    tmpLen = strlen(tmpValue);
     526    vertex = tmpValue;
     527
     528    if ((texture = strstr (vertex, "/")) != NULL)
    518529    {
    519       if (this->currentGroup->currentFace->vertexCount>0)
    520           tmpElem = tmpElem->next = new ModelFaceElement;
    521       tmpElem->next = NULL;
    522 
    523       char tmpValue [50];
    524       int tmpLen;
    525       char* vertex = NULL;
    526       char* texture = NULL;
    527       char* normal = NULL;
    528 
    529       sscanf (faceString, "%s", tmpValue);
    530       tmpLen = strlen(tmpValue);
    531       vertex = tmpValue;
    532 
    533       if ((texture = strstr (vertex, "/")) != NULL)
    534         {
    535           texture[0] = '\0';
    536           texture ++;
    537 
    538           if ((normal = strstr (texture, "/")) !=NULL)
    539             {
    540               normal[0] = '\0';
    541               normal ++;
    542             }
    543         }
    544       if (vertex)
    545         tmpElem->vertexNumber = atoi(vertex)-1;
    546       if (texture)
    547         tmpElem->texCoordNumber = atoi(texture)-1;
    548       if (normal)
    549         tmpElem->normalNumber = atoi(normal)-1;
    550 
    551       faceString += tmpLen;
    552       if (strcmp (faceString, "\0"))
    553         faceString++;
    554       this->currentGroup->currentFace->vertexCount++;
     530      texture[0] = '\0';
     531      texture ++;
     532
     533      if ((normal = strstr (texture, "/")) !=NULL)
     534      {
     535        normal[0] = '\0';
     536        normal ++;
     537      }
    555538    }
     539    if (vertex)
     540      tmpElem->vertexNumber = atoi(vertex)-1;
     541    if (texture)
     542      tmpElem->texCoordNumber = atoi(texture)-1;
     543    if (normal)
     544      tmpElem->normalNumber = atoi(normal)-1;
     545
     546    faceString += tmpLen;
     547    if (strcmp (faceString, "\0"))
     548      faceString++;
     549    this->currentGroup->currentFace->vertexCount++;
     550  }
    556551
    557552  this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount -2;
     
    575570
    576571  for (int i = 0; i < faceElemCount; i++)
    577     {
    578       if (this->currentGroup->currentFace->vertexCount > 0)
    579         tmpElem = tmpElem->next = new ModelFaceElement;
    580 
    581       tmpElem->vertexNumber = va_arg (itemlist, int);
    582       if (type & TEXCOORD)
    583         tmpElem->texCoordNumber = va_arg (itemlist, int);
    584       if (type & NORMAL)
    585         tmpElem->normalNumber = va_arg(itemlist, int);
    586       this->currentGroup->currentFace->vertexCount++;
    587     }
     572  {
     573    if (this->currentGroup->currentFace->vertexCount > 0)
     574      tmpElem = tmpElem->next = new ModelFaceElement;
     575
     576    tmpElem->vertexNumber = va_arg (itemlist, int);
     577    if (type & TEXCOORD)
     578      tmpElem->texCoordNumber = va_arg (itemlist, int);
     579    if (type & NORMAL)
     580      tmpElem->normalNumber = va_arg(itemlist, int);
     581    this->currentGroup->currentFace->vertexCount++;
     582  }
    588583  va_end(itemlist);
    589584
     
    596591 * @param matString the Material that will be set.
    597592*/
    598 bool StaticModel::setMaterial(const char* matString)
     593bool StaticModel::setMaterial(const std::string& matString)
    599594{
    600595  if (this->currentGroup->faceCount > 0)
     
    647642  ModelGroup* tmpGroup = firstGroup;
    648643  while (tmpGroup != NULL)
     644  {
     645    ModelFace* tmpFace = tmpGroup->firstFace;
     646    while (tmpFace != NULL)
    649647    {
    650       ModelFace* tmpFace = tmpGroup->firstFace;
    651       while (tmpFace != NULL)
     648      if (tmpFace->firstElem != NULL)
     649      {
     650        ModelFaceElement* firstElem = tmpFace->firstElem;
     651        ModelFaceElement* prevElem;
     652        ModelFaceElement* curElem = firstElem;
     653        ModelFaceElement* nextElem;
     654        ModelFaceElement* lastElem;
     655        // find last Element of the Chain. !! IMPORTANT:the last Element of the Chain must point to NULL, or it will resolv into an infinity-loop.
     656        while (curElem != NULL)
    652657        {
    653           if (tmpFace->firstElem != NULL)
    654             {
    655               ModelFaceElement* firstElem = tmpFace->firstElem;
    656               ModelFaceElement* prevElem;
    657               ModelFaceElement* curElem = firstElem;
    658               ModelFaceElement* nextElem;
    659               ModelFaceElement* lastElem;
    660               // find last Element of the Chain. !! IMPORTANT:the last Element of the Chain must point to NULL, or it will resolv into an infinity-loop.
    661               while (curElem != NULL)
    662                 {
    663                   prevElem = curElem;
    664                   curElem = curElem->next;
    665                 }
    666               lastElem = prevElem;
    667 
    668               curElem = firstElem;
    669               for (int j=0; j<tmpFace->vertexCount; j++)
    670                 {
    671                   if (!(nextElem = curElem->next))
    672                     nextElem = firstElem;
    673                   curElem->normalNumber = curElem->vertexNumber;
    674 
    675                   curV = Vector (this->vertices[curElem->vertexNumber*3],
    676                                  this->vertices[curElem->vertexNumber*3+1],
    677                                  this->vertices[curElem->vertexNumber*3+2]);
    678 
    679                   prevV = Vector (this->vertices[prevElem->vertexNumber*3],
    680                                   this->vertices[prevElem->vertexNumber*3+1],
    681                                   this->vertices[prevElem->vertexNumber*3+2]) - curV;
    682 
    683                   nextV = Vector (this->vertices[nextElem->vertexNumber*3],
    684                                   this->vertices[nextElem->vertexNumber*3+1],
    685                                   this->vertices[nextElem->vertexNumber*3+2]) - curV;
    686                   normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + nextV.cross(prevV);
    687 
    688                   prevElem = curElem;
    689                   curElem = curElem->next;
    690                 }
    691             }
    692           tmpFace = tmpFace->next;
     658          prevElem = curElem;
     659          curElem = curElem->next;
    693660        }
    694       tmpGroup = tmpGroup->next;
     661        lastElem = prevElem;
     662
     663        curElem = firstElem;
     664        for (int j=0; j<tmpFace->vertexCount; j++)
     665        {
     666          if (!(nextElem = curElem->next))
     667            nextElem = firstElem;
     668          curElem->normalNumber = curElem->vertexNumber;
     669
     670          curV = Vector (this->vertices[curElem->vertexNumber*3],
     671                         this->vertices[curElem->vertexNumber*3+1],
     672                         this->vertices[curElem->vertexNumber*3+2]);
     673
     674          prevV = Vector (this->vertices[prevElem->vertexNumber*3],
     675                          this->vertices[prevElem->vertexNumber*3+1],
     676                          this->vertices[prevElem->vertexNumber*3+2]) - curV;
     677
     678          nextV = Vector (this->vertices[nextElem->vertexNumber*3],
     679                          this->vertices[nextElem->vertexNumber*3+1],
     680                          this->vertices[nextElem->vertexNumber*3+2]) - curV;
     681          normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + nextV.cross(prevV);
     682
     683          prevElem = curElem;
     684          curElem = curElem->next;
     685        }
     686      }
     687      tmpFace = tmpFace->next;
    695688    }
     689    tmpGroup = tmpGroup->next;
     690  }
    696691
    697692  for (int i=0; i < this->vertices.size()/3;i++)
    698     {
    699       normArray[i].normalize();
    700       PRINTF(5)("Found Normale number %d: (%f; %f, %f).\n", i, normArray[i].x, normArray[i].y, normArray[i].z);
    701 
    702       this->addVertexNormal(normArray[i].x, normArray[i].y, normArray[i].z);
    703 
    704     }
     693  {
     694    normArray[i].normalize();
     695    PRINTF(5)("Found Normale number %d: (%f; %f, %f).\n", i, normArray[i].x, normArray[i].y, normArray[i].z);
     696
     697    this->addVertexNormal(normArray[i].x, normArray[i].y, normArray[i].z);
     698
     699  }
    705700  delete[] normArray;
    706701}
     
    721716
    722717  while (this->currentGroup != NULL)
     718  {
     719
     720    // creating a glList for the Group
     721    if ((this->currentGroup->listNumber = glGenLists(1)) == 0)
    723722    {
    724 
    725       // creating a glList for the Group
    726       if ((this->currentGroup->listNumber = glGenLists(1)) == 0)
     723      PRINTF(2)("glList could not be created for this Model\n");
     724      return false;
     725    }
     726    glNewList (this->currentGroup->listNumber, GL_COMPILE);
     727
     728    // Putting Faces to GL
     729    ModelFace* tmpFace = this->currentGroup->firstFace;
     730    while (tmpFace != NULL)
     731    {
     732      if (tmpFace->vertexCount == 0 && tmpFace->material != NULL)
     733      {
     734        if (this->currentGroup->faceMode != -1)
     735          glEnd();
     736        this->currentGroup->faceMode = 0;
     737        Material* tmpMat;
     738        if (tmpFace->material != NULL)
    727739        {
    728           PRINTF(2)("glList could not be created for this Model\n");
    729           return false;
     740          tmpFace->material->select();
     741          PRINTF(5)("using material %s for coming Faces.\n", tmpFace->material->getName());
    730742        }
    731       glNewList (this->currentGroup->listNumber, GL_COMPILE);
    732 
    733       // Putting Faces to GL
    734       ModelFace* tmpFace = this->currentGroup->firstFace;
    735       while (tmpFace != NULL)
     743      }
     744
     745      else if (tmpFace->vertexCount == 3)
     746      {
     747        if (this->currentGroup->faceMode != 3)
    736748        {
    737           if (tmpFace->vertexCount == 0 && tmpFace->material != NULL)
    738             {
    739               if (this->currentGroup->faceMode != -1)
    740                 glEnd();
    741               this->currentGroup->faceMode = 0;
    742               Material* tmpMat;
    743               if (tmpFace->material != NULL)
    744                 {
    745                   tmpFace->material->select();
    746                   PRINTF(5)("using material %s for coming Faces.\n", tmpFace->material->getName());
    747                 }
    748             }
    749 
    750           else if (tmpFace->vertexCount == 3)
    751             {
    752               if (this->currentGroup->faceMode != 3)
    753                 {
    754                   if (this->currentGroup->faceMode != -1)
    755                     glEnd();
    756                   glBegin(GL_TRIANGLES);
    757                 }
    758 
    759               this->currentGroup->faceMode = 3;
    760               PRINTF(5)("found triag.\n");
    761             }
    762 
    763           else if (tmpFace->vertexCount == 4)
    764             {
    765               if (this->currentGroup->faceMode != 4)
    766                 {
    767                   if (this->currentGroup->faceMode != -1)
    768                     glEnd();
    769                   glBegin(GL_QUADS);
    770                 }
    771               this->currentGroup->faceMode = 4;
    772               PRINTF(5)("found quad.\n");
    773             }
    774 
    775           else if (tmpFace->vertexCount > 4)
    776             {
    777               if (this->currentGroup->faceMode != -1)
    778                 glEnd();
    779               glBegin(GL_POLYGON);
    780               PRINTF(5)("Polygon with %i faces found.", tmpFace->vertexCount);
    781               this->currentGroup->faceMode = tmpFace->vertexCount;
    782             }
    783 
    784           ModelFaceElement* tmpElem = tmpFace->firstElem;
    785           while (tmpElem != NULL)
    786             {
    787               //      PRINTF(2)("%s\n", tmpElem->value);
    788               this->addGLElement(tmpElem);
    789               tmpElem = tmpElem->next;
    790             }
    791           tmpFace = tmpFace->next;
     749          if (this->currentGroup->faceMode != -1)
     750            glEnd();
     751          glBegin(GL_TRIANGLES);
    792752        }
    793       glEnd();
    794       glEndList();
    795 
    796       this->currentGroup = this->currentGroup->next;
     753
     754        this->currentGroup->faceMode = 3;
     755        PRINTF(5)("found triag.\n");
     756      }
     757
     758      else if (tmpFace->vertexCount == 4)
     759      {
     760        if (this->currentGroup->faceMode != 4)
     761        {
     762          if (this->currentGroup->faceMode != -1)
     763            glEnd();
     764          glBegin(GL_QUADS);
     765        }
     766        this->currentGroup->faceMode = 4;
     767        PRINTF(5)("found quad.\n");
     768      }
     769
     770      else if (tmpFace->vertexCount > 4)
     771      {
     772        if (this->currentGroup->faceMode != -1)
     773          glEnd();
     774        glBegin(GL_POLYGON);
     775        PRINTF(5)("Polygon with %i faces found.", tmpFace->vertexCount);
     776        this->currentGroup->faceMode = tmpFace->vertexCount;
     777      }
     778
     779      ModelFaceElement* tmpElem = tmpFace->firstElem;
     780      while (tmpElem != NULL)
     781      {
     782        //      PRINTF(2)("%s\n", tmpElem->value);
     783        this->addGLElement(tmpElem);
     784        tmpElem = tmpElem->next;
     785      }
     786      tmpFace = tmpFace->next;
    797787    }
     788    glEnd();
     789    glEndList();
     790
     791    this->currentGroup = this->currentGroup->next;
     792  }
    798793}
    799794
     
    814809  ModelFace* tmpFace;              //!< the temporary face referece
    815810
     811  bool warned = false;
     812
    816813  /* count the number of triangles */
    817814  /* now iterate through all groups and build up the triangle list */
     
    834831      else if( tmpFace->vertexCount > 4)
    835832      {
    836         PRINTF(1)("This model (%s) got over 4 vertices per face <=> conflicts in the CD engine!\n", this->getName());
    837       //exit(0);
     833        if (!warned)
     834        {
     835          PRINTF(2)("This model (%s) got over 4 vertices per face <=> conflicts in the CD engine!\n", this->getName());
     836          warned = true;
     837        }
     838        //exit(0);
    838839      }
    839840      tmpFace = tmpFace->next;
     
    858859  while( this->currentGroup != NULL)
    859860  {
    860       // Putting Faces to GL
     861    // Putting Faces to GL
    861862    tmpFace = this->currentGroup->firstFace;
    862863    while( tmpFace != NULL)
     
    931932
    932933  if (elem->texCoordNumber != -1)
    933     {
    934       if (likely(elem->texCoordNumber < this->pModelInfo.numTexCoor))
    935         glTexCoord2fv(&this->vTexture[0] + elem->texCoordNumber * 2);
    936       else
    937         PRINTF(2)("TextureCoordinate %d is not in the List (max: %d)\nThe Model might be incomplete\n",
    938                   elem->texCoordNumber, this->pModelInfo.numTexCoor);
    939     }
     934  {
     935    if (likely(elem->texCoordNumber < this->pModelInfo.numTexCoor))
     936      glTexCoord2fv(&this->vTexture[0] + elem->texCoordNumber * 2);
     937    else
     938      PRINTF(2)("TextureCoordinate %d is not in the List (max: %d)\nThe Model might be incomplete\n",
     939                elem->texCoordNumber, this->pModelInfo.numTexCoor);
     940  }
    940941  if (elem->normalNumber != -1)
    941     {
     942  {
    942943    if (likely(elem->normalNumber < this->pModelInfo.numNormals))
    943944      glNormal3fv(&this->normals[0] + elem->normalNumber * 3);
    944945    else
    945         PRINTF(2)("Normal %d is not in the List (max: %d)\nThe Model might be incomplete",
    946                   elem->normalNumber, this->pModelInfo.numNormals);
    947     }
     946      PRINTF(2)("Normal %d is not in the List (max: %d)\nThe Model might be incomplete",
     947                elem->normalNumber, this->pModelInfo.numNormals);
     948  }
    948949  if (elem->vertexNumber != -1)
    949     {
    950       if (likely(elem->vertexNumber < this->pModelInfo.numVertices))
    951           glVertex3fv(&this->vertices[0]+ elem->vertexNumber * 3);
    952       else
    953         PRINTF(2)("Vertex %d is not in the List (max: %d)\nThe Model might be incomplete",
    954                   elem->vertexNumber, this->pModelInfo.numVertices);
    955     }
     950  {
     951    if (likely(elem->vertexNumber < this->pModelInfo.numVertices))
     952      glVertex3fv(&this->vertices[0]+ elem->vertexNumber * 3);
     953    else
     954      PRINTF(2)("Vertex %d is not in the List (max: %d)\nThe Model might be incomplete",
     955                elem->vertexNumber, this->pModelInfo.numVertices);
     956  }
    956957
    957958}
  • trunk/src/lib/graphics/importer/static_model.h

    r6423 r7221  
    1313#include <vector>
    1414#include <list>
    15 
    16 // FORWARD DECLARATION //
    17 template<class T> class tArray;
    1815
    1916// definition of different modes for setting up Faces
     
    7067  void cleanup();
    7168
    72   char*        name;           //!< the Name of the Group. this is an identifier, that can be accessed via the draw (char* name) function.
     69  std::string  name;           //!< the Name of the Group. this is an identifier, that can be accessed via the draw (std::string name) function.
    7370  GLubyte*     indices;        //!< The indices of the Groups. Needed for vertex-arrays
    7471  GLuint       listNumber;     //!< The number of the GL-List this Group gets.
     
    9895{
    9996 public:
    100   StaticModel(const char* modelName = NULL);
     97  StaticModel(const std::string& modelName = "");
    10198  virtual ~StaticModel();
    10299
    103100  virtual void draw() const;
    104101  void draw(int groupNumber) const;
    105   void draw(char* groupName) const;
     102  void draw(const std::string& groupName) const;
    106103
    107104  void rebuild();
    108105
    109106  Material* addMaterial(Material* material);
    110   Material* addMaterial(const char* materialName);
     107  Material* addMaterial(const std::string& materialName);
    111108
    112   bool addGroup(const char* groupString);
     109  bool addGroup(const std::string& groupString);
    113110
    114   bool addVertex(const char* vertexString);
     111  bool addVertex(const std::string& vertexString);
    115112  bool addVertex(float x, float y, float z);
    116113
    117   bool addFace(const char* faceString);
     114  bool addFace(const std::string& faceString);
    118115  bool addFace(int faceElemCount, VERTEX_FORMAT type, ...);
    119116
    120   bool addVertexNormal(const char* normalString);
     117  bool addVertexNormal(const std::string& normalString);
    121118  bool addVertexNormal(float x, float y, float z);
    122119
    123   bool addVertexTexture(const char* vTextureString);
     120  bool addVertexTexture(const std::string& vTextureString);
    124121  bool addVertexTexture(float u, float v);
    125122
    126   bool setMaterial(const char* mtlString);
     123  bool setMaterial(const std::string& mtlString);
    127124  bool setMaterial(Material* mtl);
    128125
     
    133130  void cubeModel();
    134131
    135   Material* findMaterialByName(const char* materialName);
     132  Material* findMaterialByName(const std::string& materialName);
    136133
    137134 protected:
  • trunk/src/lib/graphics/importer/texture.cc

    r6871 r7221  
    3232 *  Constructor for a Texture
    3333*/
    34 Texture::Texture(const char* imageName, GLenum target)
     34Texture::Texture(const std::string& imageName, GLenum target)
    3535{
    3636  this->setClassID(CL_TEXTURE, "Texture");
     
    4141  this->priority = 0.5;
    4242
    43   if (imageName != NULL)
     43  if (!imageName.empty())
    4444  {
    4545    this->setName(imageName);
     
    6767 * @param imageName The image to load
    6868*/
    69 bool Texture::loadImage(const char* imageName, GLenum target)
     69bool Texture::loadImage(const std::string& imageName, GLenum target)
    7070{
    7171  if (Texture::texturesEnabled)
     
    8181      this->texture = 0;
    8282    }
    83     if (imageName != NULL)
     83    if (!imageName.empty())
    8484    {
    8585      SDL_Surface* tmpSurf;
     
    8787        glDeleteTextures(1, &this->texture);
    8888      // load the new Image to memory
    89       tmpSurf = IMG_Load(imageName);
     89      tmpSurf = IMG_Load(imageName.c_str());
    9090      if(tmpSurf != NULL)
    9191      {
  • trunk/src/lib/graphics/importer/texture.h

    r6981 r7221  
    1818  {
    1919    public:
    20       Texture(const char* imageName = NULL, GLenum target = GL_TEXTURE_2D);
     20      Texture(const std::string& imageName = "", GLenum target = GL_TEXTURE_2D);
    2121  //  Texture(TEXTURE_TYPE type, int resolution);
    2222      virtual ~Texture();
    2323
    24       bool loadImage(const char* imageName, GLenum target = GL_TEXTURE_2D);
     24      bool loadImage(const std::string& imageName, GLenum target = GL_TEXTURE_2D);
    2525      virtual bool rebuild();
    2626
  • trunk/src/lib/graphics/importer/texture_sequence.cc

    r6624 r7221  
    124124 * @returns true on success
    125125 */
    126 bool TextureSequence::addFrame(const char* imageName)
     126bool TextureSequence::addFrame(const std::string& imageName)
    127127{
    128   if (imageName == NULL)
    129     return false;
    130 
    131   SDL_Surface* addSurface = IMG_Load(imageName);
     128  SDL_Surface* addSurface = IMG_Load(imageName.c_str());
    132129  bool success = this->addFrame(addSurface);
    133130  delete addSurface;
  • trunk/src/lib/graphics/importer/texture_sequence.h

    r7195 r7221  
    2323    bool loadImageSeries(unsigned int count, ...);
    2424    bool loadImageSeries(unsigned int count, va_list textureNames);
    25     bool addFrame(const char* image);
     25    bool addFrame(const std::string& image);
    2626    bool addFrame(SDL_Surface* surface);
    2727    bool addFrame(GLuint texture);
  • trunk/src/lib/graphics/render2D/billboard.cc

    r7193 r7221  
    7878void Billboard::loadParams(const TiXmlElement* root)
    7979{
    80   LoadParam(root, "texture", this, Billboard, setTexture)
     80  LoadParam(root, "texture", this->material, Material, setDiffuseMap)
    8181      .describe("the texture-file to load onto the Billboard");
    8282
     
    100100 * @param textureFile The texture-file to load onto the crosshair
    101101 */
    102 void Billboard::setTexture(const char* textureFile)
     102void Billboard::setTexture(const std::string& textureFile)
    103103{
    104104  this->material->setDiffuseMap(textureFile);
  • trunk/src/lib/graphics/render2D/billboard.h

    r6815 r7221  
    3030
    3131    void setSize(float sizeX, float sizeY);
    32     void setTexture(const char* textureFile);
     32    void setTexture(const std::string& textureFile);
    3333    void attachTo(PNode* pnode);
    3434
  • trunk/src/lib/graphics/render2D/element_2d.cc

    r7199 r7221  
    180180 * @param alignment the alignment @see loadParams
    181181*/
    182 void Element2D::setAlignment(const char* alignment)
    183 {
    184   if (!strcmp(alignment, "center"))
     182void Element2D::setAlignment(const std::string& alignment)
     183{
     184  if (alignment == "center")
    185185    this->setAlignment(E2D_ALIGN_CENTER);
    186   else if (!strcmp(alignment, "left"))
     186  else if (alignment == "left")
    187187    this->setAlignment(E2D_ALIGN_LEFT);
    188   else if (!strcmp(alignment, "right"))
     188  else if (alignment == "right")
    189189    this->setAlignment(E2D_ALIGN_RIGHT);
    190   else if (!strcmp(alignment, "screen-center"))
     190  else if (alignment == "screen-center")
    191191    this->setAlignment(E2D_ALIGN_SCREEN_CENTER);
    192192}
     
    213213/**
    214214 * sets the layer onto which this 2D-element is projected to.
    215  * @param layer the layer @see loadParams @see Element2D::charToLayer2D(const char* layer)
    216  */
    217 void Element2D::setLayer(const char* layer)
     215 * @param layer the layer @see loadParams @see Element2D::charToLayer2D(const std::string& layer)
     216 */
     217void Element2D::setLayer(const std::string& layer)
    218218{
    219219  this->setLayer(Element2D::charToLayer2D(layer));
     
    235235 * @param bindNode the name of the Node (should be existing)
    236236 */
    237 void Element2D::setBindNode(const char* bindNode)
     237void Element2D::setBindNode(const std::string& bindNode)
    238238{
    239239  const PNode* tmpBindNode = dynamic_cast<const PNode*>(ClassList::getObject(bindNode, CL_PARENT_NODE));
     
    572572 * @param childName the name of the child to add to this PNode
    573573 */
    574 void Element2D::addChild2D (const char* childName)
     574void Element2D::addChild2D (const std::string& childName)
    575575{
    576576  Element2D* childNode = dynamic_cast<Element2D*>(ClassList::getObject(childName, CL_ELEMENT_2D));
     
    651651 * @param parentName the name of the Parent to set to this Element2D
    652652 */
    653 void Element2D::setParent2D (const char* parentName)
     653void Element2D::setParent2D (const std::string& parentName)
    654654{
    655655  Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D));
     
    658658  else
    659659    PRINTF(2)("Not Found Element2D's (%s::%s) new Parent by Name: %s\n",
    660                 this->getClassName(), this->getName(), parentName);
     660                this->getClassName(), this->getName(), parentName.c_str());
    661661}
    662662
     
    704704 * @param bias the speed to iterate to this new Positions
    705705 */
    706 void Element2D::setParentSoft2D(const char* parentName, float bias)
     706void Element2D::setParentSoft2D(const std::string& parentName, float bias)
    707707{
    708708  Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D));
     
    724724 * @param parentMode a String representing this parentingMode
    725725 */
    726 void Element2D::setParentMode2D (const char* parentingMode)
    727 {
    728   this->setParentMode2D(Element2D::charToParentingMode2D(parentingMode));
     726void Element2D::setParentMode2D (const std::string& parentingMode)
     727{
     728  this->setParentMode2D(Element2D::stringToParentingMode2D(parentingMode));
    729729}
    730730
     
    952952            this->relCoordinate.y,
    953953            this->getAbsDir2D(),
    954             Element2D::parentingModeToChar2D(parentMode),
     954            Element2D::parentingModeToString2D(parentMode),
    955955            Element2D::layer2DToChar(this->layer));
    956956
     
    10741074 * @return the converted string
    10751075 */
    1076 const char* Element2D::parentingModeToChar2D(int parentingMode)
     1076const char* Element2D::parentingModeToString2D(int parentingMode)
    10771077{
    10781078  if (parentingMode == E2D_PARENT_LOCAL_ROTATE)
     
    10931093 * @return the int corresponding to the named parentingMode
    10941094 */
    1095 E2D_PARENT_MODE Element2D::charToParentingMode2D(const char* parentingMode)
    1096 {
    1097   if (!strcmp(parentingMode, "local-rotate"))
     1095E2D_PARENT_MODE Element2D::stringToParentingMode2D(const std::string& parentingMode)
     1096{
     1097  if (parentingMode == "local-rotate")
    10981098    return (E2D_PARENT_LOCAL_ROTATE);
    1099   else  if (!strcmp(parentingMode, "rotate-movement"))
     1099  else  if (parentingMode == "rotate-movement")
    11001100    return (E2D_PARENT_ROTATE_MOVEMENT);
    1101   else  if (!strcmp(parentingMode, "movement"))
     1101  else  if (parentingMode == "movement")
    11021102    return (E2D_PARENT_MOVEMENT);
    1103   else  if (!strcmp(parentingMode, "all"))
     1103  else  if (parentingMode == "all")
    11041104    return (E2D_PARENT_ALL);
    1105   else  if (!strcmp(parentingMode, "rotate-and-move"))
     1105  else  if (parentingMode == "rotate-and-move")
    11061106    return (E2D_PARENT_ROTATE_AND_MOVE);
    11071107}
     
    11391139 * @returns the E2D_LAYER on success, E2D_DEFAULT_LAYER on error.
    11401140 */
    1141 E2D_LAYER Element2D::charToLayer2D(const char* layer)
    1142 {
    1143   if (!strcmp(layer, "top"))
     1141E2D_LAYER Element2D::charToLayer2D(const std::string& layer)
     1142{
     1143  if (layer =="top")
    11441144    return (E2D_LAYER_TOP);
    1145   else  if (!strcmp(layer, "medium"))
     1145  else  if (layer == "medium")
    11461146    return (E2D_LAYER_MEDIUM);
    1147   else  if (!strcmp(layer, "bottom"))
     1147  else  if (layer == "bottom")
    11481148    return (E2D_LAYER_BOTTOM);
    1149   else  if (!strcmp(layer, "below-all"))
     1149  else  if (layer == "below-all")
    11501150    return (E2D_LAYER_BELOW_ALL);
    11511151  else
  • trunk/src/lib/graphics/render2D/element_2d.h

    r7052 r7221  
    102102    /** @param alignment the new Alignment of the 2D-Element */
    103103    inline void setAlignment(E2D_ALIGNMENT alignment) { this->alignment = alignment; };
    104     void setAlignment(const char* alignment);
     104    void setAlignment(const std::string& alignment);
    105105    inline E2D_ALIGNMENT getAlignment() const { return this->alignment; };
    106106
    107107    // LAYERING //
    108108    void setLayer(E2D_LAYER layer);
    109     void setLayer(const char* layer);
     109    void setLayer(const std::string& layer);
    110110    /** @returns the Layer this Element is drawn to */
    111111    inline E2D_LAYER getLayer() const { return this->layer; };
     
    121121    /** @param bindNode the Node this 2D-element should follow. if NULL the Element will not follow anything */
    122122    inline void setBindNode(const PNode* bindNode) { this->bindNode = bindNode; };
    123     void setBindNode(const char* bindNode);
     123    void setBindNode(const std::string& bindNode);
    124124    inline const PNode* getBindNode() const { return this->bindNode; };
    125125
     
    181181
    182182    void addChild2D (Element2D* child);
    183     void addChild2D (const char* childName);
     183    void addChild2D (const std::string& childName);
    184184    void removeChild2D (Element2D* child);
    185185    void remove2D();
     
    187187    /** @param parent the new parent of this Element2D */
    188188    void setParent2D (Element2D* parent) { parent->addChild2D(this); };
    189     void setParent2D (const char* parentName);
     189    void setParent2D (const std::string& parentName);
    190190    /** @returns the parent of this Element2D */
    191191    inline Element2D* getParent2D () const { return this->parent; };
     
    194194
    195195    void setParentSoft2D(Element2D* parentNode, float bias = 1.0);
    196     void setParentSoft2D(const char* parentName, float bias = 1.0);
     196    void setParentSoft2D(const std::string& parentName, float bias = 1.0);
    197197
    198198    void setParentMode2D (E2D_PARENT_MODE parentMode);
    199     void setParentMode2D (const char* parentingMode);
     199    void setParentMode2D (const std::string& parentingMode);
    200200    /** @returns the Parenting mode of this node */
    201201    int getParentMode2D() const { return this->parentMode; };
     
    212212
    213213    // helper functions //
    214     static const char* parentingModeToChar2D(int parentingMode);
    215     static E2D_PARENT_MODE charToParentingMode2D(const char* parentingMode);
     214    static const char* parentingModeToString2D(int parentingMode);
     215    static E2D_PARENT_MODE stringToParentingMode2D(const std::string& parentingMode);
    216216
    217217    static const char* layer2DToChar(E2D_LAYER layer);
    218     static E2D_LAYER charToLayer2D(const char* layer);
     218    static E2D_LAYER charToLayer2D(const std::string& layer);
    219219
    220220  private:
  • trunk/src/lib/graphics/shader.cc

    r7193 r7221  
    3636 * standard constructor
    3737*/
    38 Shader::Shader (const char* vertexShaderFile, const char* fragmentShaderFile)
     38Shader::Shader (const std::string& vertexShaderFile, const std::string& fragmentShaderFile)
    3939{
    4040   this->setClassID(CL_SHADER, "Shader");
    4141
    42    this->fragmentShaderFile = NULL;
    43    this->vertexShaderFile = NULL;
     42   this->fragmentShaderFile = "";
     43   this->vertexShaderFile = "";
    4444   this->shaderProgram = 0;
    4545   this->vertexShader = 0;
     
    5252       this->shaderProgram = glCreateProgramObjectARB();
    5353
    54        if (vertexShaderFile != NULL)
     54       if (!vertexShaderFile.empty())
    5555         this->loadShaderProgramm(SHADER_VERTEX, vertexShaderFile);
    56        if (fragmentShaderFile != NULL)
     56       if (!fragmentShaderFile.empty())
    5757         this->loadShaderProgramm(SHADER_FRAGMENT, fragmentShaderFile);
    5858       glLinkProgramARB(this->shaderProgram);
     
    103103}
    104104
    105 Shader* Shader::getShader(const char* vertexShaderFile, const char* fragmentShaderFile)
     105Shader* Shader::getShader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile)
    106106{
    107107  return (Shader*)ResourceManager::getInstance()->load(vertexShaderFile, SHADER,  RP_LEVEL, fragmentShaderFile);
     
    116116
    117117
    118 bool Shader::loadShaderProgramm(SHADER_TYPE type, const char* fileName)
     118bool Shader::loadShaderProgramm(SHADER_TYPE type, const std::string& fileName)
    119119{
    120120  GLhandleARB shader = 0;
     
    129129  if (type == SHADER_VERTEX && GLEW_ARB_vertex_shader)
    130130  {
    131     this->vertexShaderFile = new char[strlen(fileName)+1];
    132     strcpy(this->vertexShaderFile, fileName);
     131    this->vertexShaderFile = fileName;
    133132
    134133    shader = this->vertexShader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
     
    137136  if (type == SHADER_FRAGMENT && GLEW_ARB_fragment_shader)
    138137  {
    139     this->fragmentShaderFile = new char[strlen(fileName)+1];
    140     strcpy(this->fragmentShaderFile, fileName);
     138    this->fragmentShaderFile = fileName;
    141139
    142140    shader = this->fragmentShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
     
    146144  {
    147145    GLint status = 0;
    148     glShaderSourceARB(shader, program->size(), (const char**)&(*program)[0], NULL);
     146    /// FIXME do it back
     147    //    glShaderSourceARB(shader, program->size(), (const std::string&)&(*program)[0], NULL);
    149148    glCompileShaderARB(shader);
    150149    // checking on error.
     
    160159}
    161160
    162 char* Shader::fileRead(const char* fileName)
     161char* Shader::fileRead(const std::string& fileName)
    163162{
    164163  FILE* fileHandle;
     
    167166  int count = 0;
    168167
    169   if (fileName == NULL)
     168  if (fileName.empty())
    170169    return NULL;
    171170
    172   fileHandle = fopen(fileName, "rt");
     171  fileHandle = fopen(fileName.c_str(), "rt");
    173172
    174173  if (fileHandle == NULL)
     
    187186
    188187
    189 std::vector<char*>* Shader::fileReadArray(const char* fileName)
     188std::vector<char*>* Shader::fileReadArray(const std::string& fileName)
    190189{
    191190  FILE*    stream;           //< The stream we use to read the file.
    192191
    193   if( (stream = fopen (fileName, "rt")) == NULL)
    194   {
    195     PRINTF(1)("Shader could not open %s\n", fileName);
     192  if( (stream = fopen (fileName.c_str(), "rt")) == NULL)
     193  {
     194    PRINTF(1)("Shader could not open %s\n", fileName.c_str());
    196195    return NULL;
    197196  }
     
    234233  if (type == SHADER_VERTEX && this->vertexShader != 0)
    235234  {
    236     delete[] this->vertexShaderFile;
    237     this->vertexShaderFile = NULL;
     235    this->vertexShaderFile = "";
    238236    glDetachObjectARB(this->shaderProgram, this->vertexShader);
    239237    glDeleteObjectARB(this->vertexShader);
     
    245243  else if (type == SHADER_FRAGMENT && this->fragmentShader != 0)
    246244  {
    247     delete[] this->fragmentShaderFile;
    248     this->fragmentShaderFile = NULL;
     245    this->fragmentShaderFile = "";
    249246    glDetachObjectARB(this->shaderProgram, this->fragmentShader);
    250247    glDeleteObjectARB(this->fragmentShader);
  • trunk/src/lib/graphics/shader.h

    r7195 r7221  
    2727
    2828  public:
    29   Shader(const char* vertexShaderFile = NULL, const char* fragmentShaderFile = NULL);
     29  Shader(const std::string& vertexShaderFile = "", const std::string& fragmentShaderFile = "");
    3030  virtual ~Shader();
    31   static Shader* getShader(const char* vertexShaderFile, const char* fragmentShaderFile);
     31  static Shader* getShader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile);
    3232  static bool unload(Shader* shader);
    3333
    34   bool loadShaderProgramm(SHADER_TYPE type, const char* fileName);
     34  bool loadShaderProgramm(SHADER_TYPE type, const std::string& fileName);
    3535  void activateShader();
    3636  static void deactivateShader();
    3737  void deleteProgram(SHADER_TYPE type);
    3838
    39   char* fileRead(const char* fileName);
    40   std::vector<char*>* fileReadArray(const char* fileName);
     39  char* fileRead(const std::string& fileName);
     40  std::vector<char*>* fileReadArray(const std::string& fileName);
    4141
    4242  static bool checkShaderAbility();
     
    5454
    5555 private:
    56    char*                  fragmentShaderFile;
    57    char*                  vertexShaderFile;
     56   std::string            fragmentShaderFile;
     57   std::string            vertexShaderFile;
    5858   GLhandleARB            shaderProgram;
    5959   GLhandleARB            vertexShader;
  • trunk/src/lib/graphics/text_engine/font.cc

    r6609 r7221  
    3737 * @param fontSize the Size of the Font in Pixels
    3838 */
    39 Font::Font(const char* fontFile, unsigned int renderSize)
     39Font::Font(const std::string& fontFile, unsigned int renderSize)
    4040{
    4141  this->init();
     
    4444  this->setStyle("c");
    4545
    46   if (fontFile != NULL)
     46  if (!fontFile.empty())
    4747    this->loadFontFromTTF(fontFile);
    4848}
     
    5252 * @param imageFile the ImageFile to load the Font From.
    5353 */
    54 Font::Font(const char* imageFile)
     54Font::Font(const std::string& imageFile)
    5555{
    5656  this->init();
     
    5858  //  this->setSize(fontSize);
    5959  SDL_Surface* image = NULL;
    60   if (imageFile != NULL)
    61     image = IMG_Load(imageFile);
     60  if (!imageFile.empty())
     61    image = IMG_Load(imageFile.c_str());
    6262  else
    6363    return;
     
    6868  }
    6969  else
    70     PRINTF(1)("loading from surface %s failed: %s\n", imageFile, IMG_GetError());
     70    PRINTF(1)("loading from surface %s failed: %s\n", imageFile.c_str(), IMG_GetError());
    7171}
    7272
     
    114114
    115115  //! @todo check if we really do not need to delete the fastTextureID here.
    116 //   if (this->fastTextureID != 0)
    117 //     if(glIsTexture(this->fastTextureID))
    118 //       glDeleteTextures(1, &this->fastTextureID);
     116  //   if (this->fastTextureID != 0)
     117  //     if(glIsTexture(this->fastTextureID))
     118  //       glDeleteTextures(1, &this->fastTextureID);
    119119
    120120  // erease this font out of the memory.
     
    140140 * @returns true if loaded, false if something went wrong, or if a font was loaded before.
    141141 */
    142 bool Font::loadFontFromTTF(const char* fontFile)
     142bool Font::loadFontFromTTF(const std::string& fontFile)
    143143{
    144144  // checking for existent Font.
     
    222222 *   i: italic, b: bold, u, underline
    223223 */
    224 void Font::setStyle(const char* renderStyle)
     224void Font::setStyle(const std::string& renderStyle)
    225225{
    226226  this->renderStyle = TTF_STYLE_NORMAL;
    227227
    228   for (int i = 0; i < strlen(renderStyle); i++)
    229     if (strncmp(renderStyle+i, "b", 1) == 0)
     228  for (int i = 0; i < renderStyle.size(); i++)
     229  {
     230    if (renderStyle[i] == 'b')
    230231      this->renderStyle |= TTF_STYLE_BOLD;
    231   else if (strncmp(renderStyle+i, "i", 1) == 0)
    232     this->renderStyle |= TTF_STYLE_ITALIC;
    233   else if (strncmp(renderStyle+i, "u", 1) == 0)
    234     this->renderStyle |= TTF_STYLE_UNDERLINE;
    235 
     232    else if (renderStyle[i] == 'i')
     233      this->renderStyle |= TTF_STYLE_ITALIC;
     234    else if (renderStyle[i] == 'u')
     235      this->renderStyle |= TTF_STYLE_UNDERLINE;
     236  }
    236237  if (likely(this->fontTTF != NULL))
    237238    TTF_SetFontStyle(this->fontTTF, this->renderStyle);
    238 //  else
    239 //    PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n");
     239  //  else
     240  //    PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n");
    240241}
    241242
     
    247248 * @param fileName the File to write the image into.
    248249 */
    249 void Font::createAsciiImage(const char* fileName, unsigned int size) const
     250void Font::createAsciiImage(const std::string& fileName, unsigned int size) const
    250251{
    251252  if (this->fontTTF == NULL)
     
    258259  SDL_Rect tmpRect; // this represents a Rectangle for blitting.
    259260  SDL_Surface* tmpSurf =  SDL_CreateRGBSurface(SDL_SWSURFACE,
    260                                                height*size, height*size,
    261                                                32,
     261                          height*size, height*size,
     262                          32,
    262263#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
    263                                                0x000000FF,
    264                                                0x0000FF00,
    265                                                0x00FF0000,
    266                                                0xFF000000
     264                          0x000000FF,
     265                          0x0000FF00,
     266                          0x00FF0000,
     267                          0xFF000000
    267268#else
    268                                                0xFF000000,
    269                                                0x00FF0000,
    270                                                0x0000FF00,
    271                                                0x000000FF
     269                          0xFF000000,
     270                          0x00FF0000,
     271                          0x0000FF00,
     272                          0x000000FF
    272273#endif
    273274                                              );
     
    299300    }
    300301  }
    301   SDL_SaveBMP(tmpSurf, fileName);
     302  SDL_SaveBMP(tmpSurf, fileName.c_str());
    302303  SDL_FreeSurface(tmpSurf);
    303304}
     
    409410
    410411  this->initGlyphs(32, numberOfGlyphs);
    411 //  this->glyphArray[32]->width = .5f; //!< @todo find out the real size of a Space
     412  //  this->glyphArray[32]->width = .5f; //!< @todo find out the real size of a Space
    412413
    413414  int rectSize = this->findOptimalFastTextureSize();
     
    418419  SDL_Rect tmpRect; // this represents a Rectangle for blitting.
    419420  SDL_Surface* tmpSurf =  SDL_CreateRGBSurface(SDL_SWSURFACE,
    420                                                rectSize, rectSize,
    421                                                32,
     421                          rectSize, rectSize,
     422                          32,
    422423#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
    423                                                0x000000FF,
    424                                                0x0000FF00,
    425                                                0x00FF0000,
    426                                                0xFF000000
     424                          0x000000FF,
     425                          0x0000FF00,
     426                          0x00FF0000,
     427                          0xFF000000
    427428#else
    428                                                0xFF000000,
    429                                                0x00FF0000,
    430                                                0x0000FF00,
    431                                                0x000000FF
     429                          0xFF000000,
     430                          0x00FF0000,
     431                          0x0000FF00,
     432                          0x000000FF
    432433#endif
    433434                                              );
     
    457458        break;
    458459      }
    459           // reading in the new Glyph
     460      // reading in the new Glyph
    460461      if (likely(this->fontTTF != NULL))
    461462      {
     
    521522  for (int i = from; i <= lastGlyph; i++)
    522523  {
    523       // setting up all the Glyphs we like.
     524    // setting up all the Glyphs we like.
    524525    glyphArray[i] = getGlyphMetrics(i);
    525526  }
     
    555556      if((tmpGlyph = this->glyphArray[i]) != NULL)
    556557      {
    557               // getting the height of the highest Glyph in the Line.
     558        // getting the height of the highest Glyph in the Line.
    558559        if (tmpGlyph->height*this->renderSize > maxLineHeight)
    559560          maxLineHeight = (int)(tmpGlyph->height*this->renderSize);
     
    563564          x = 0;
    564565          y = y + maxLineHeight;
    565                   //maxLineHeight = 0;
     566          //maxLineHeight = 0;
    566567        }
    567568        if (y + maxLineHeight + 1 > size)
     
    592593  if(style==TTF_STYLE_NORMAL)
    593594    PRINTF(0)(" normal");
    594   else {
     595  else
     596  {
    595597    if(style&TTF_STYLE_BOLD)
    596598      PRINTF(0)(" bold");
  • trunk/src/lib/graphics/text_engine/font.h

    r6609 r7221  
    5555{
    5656  public:
    57     Font(const char* fontFile,
     57    Font(const std::string& fontFile,
    5858         unsigned int renderSize);
    59     Font(const char* imageFile);
     59    Font(const std::string& imageFile);
    6060    Font(char** xpmArray);
    6161    virtual ~Font();
     
    6464
    6565  //  font
    66     bool loadFontFromTTF(const char* fontFile);
     66    bool loadFontFromTTF(const std::string& fontFile);
    6767    bool loadFontFromSDL_Surface(SDL_Surface* surface);
    6868
    69     void setStyle(const char* renderStyle);
     69    void setStyle(const std::string& renderStyle);
    7070
    7171    /** @returns a Pointer to the Array of Glyphs */
     
    7878    inline static Font* getDefaultFont() { if (Font::defaultFont == NULL) initDefaultFont(); return Font::defaultFont; };
    7979
    80     void createAsciiImage(const char* fileName, unsigned int size) const;
     80    void createAsciiImage(const std::string& fileName, unsigned int size) const;
    8181    static void initDefaultFont();
    8282    static void removeDefaultFont();
  • trunk/src/lib/graphics/text_engine/text.cc

    r7193 r7221  
    3232 * @param type The renderType to display this font in
    3333 */
    34 Text::Text(const char* fontFile, unsigned int textSize)
     34Text::Text(const std::string& fontFile, unsigned int textSize)
    3535{
    3636  this->init();
    3737
    38   if (fontFile != NULL)
     38  if (!fontFile.empty())
    3939    this->setFont(fontFile, FONT_DEFAULT_RENDER_SIZE);
    4040  this->setSizeY2D(textSize);
     
    5050  if (this->font != NULL && this->font != Font::getDefaultFont())
    5151    ResourceManager::getInstance()->unload(this->font);
    52 
    53   if (this->text)
    54     delete[] this->text;
    5552}
    5653
     
    6461  // initialize this Text
    6562  this->font = NULL;
    66   this->text = NULL;
    67   this->externText = NULL;
     63  this->text = "";
    6864  this->setAlignment(TEXT_DEFAULT_ALIGNMENT);
    6965  this->blending = TEXT_DEFAULT_BLENDING;
    7066  this->color = TEXT_DEFAULT_COLOR;
    7167  this->setSize(TEXT_DEFAULT_SIZE);
    72   this->setText(NULL);
     68  this->setText("");
    7369}
    7470
     
    7874 * @param fontSize the Size of the Font
    7975 */
    80 void Text::setFont(const char* fontFile, unsigned int fontSize)
     76void Text::setFont(const std::string& fontFile, unsigned int fontSize)
    8177{
    8278  Font* tmpFont;
     
    9086
    9187  // load a new Font
    92   if (fontFile != NULL)
     88  if (!fontFile.empty())
    9389  {
    9490    tmpFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, (int)fontSize);
     
    9692      this->font = tmpFont;
    9793    else
    98       PRINTF(2)("Font %s could not be loaded, probably file not found\n", fontFile);
     94      PRINTF(2)("Font %s could not be loaded, probably file not found\n", fontFile.c_str());
    9995  }
    10096}
     
    104100 * @param text the new text to set
    105101 */
    106 void Text::setText(const char* text, bool isExtern)
    107 {
    108   if (isExtern)
    109   {
    110     this->externText = text;
    111 
    112     if (unlikely(this->text != NULL))
    113     {
    114       delete[] this->text;
    115       this->text = NULL;
    116     }
    117   }
    118   else
    119   {
    120     this->externText = NULL;
    121     if (this->text)
    122       delete[] this->text;
    123     if (text != NULL)
    124     {
    125       this->text = new char[strlen(text)+1];
    126       strcpy(this->text, text);
    127     }
    128     else
    129       this->text = NULL;
    130   }
     102void Text::setText(const std::string& text)
     103{
     104  this->text = text;
    131105
    132106  // setting up the Text-Width if DYNAMIC
     
    138112
    139113    float width = 0;
    140     const char* tmpText = this->externText;
    141     if (this->externText == NULL)
    142       tmpText = this->text;
    143     if (tmpText != NULL)
     114    if (!this->text.empty())
    144115    {
    145       while (*tmpText != '\0')
     116      for (unsigned int i = 0; i < this->text.size(); i++)
    146117      {
    147         if(glyphArray[*tmpText] != NULL)
     118        if(glyphArray[this->text[i]] != NULL)
    148119        {
    149           width += glyphArray[*tmpText]->advance;
     120          width += glyphArray[this->text[i]]->advance;
    150121        }
    151         tmpText++;
    152122      }
    153123      this->setSizeX2D(width *this->getSizeY2D());
     
    190160    glBindTexture(GL_TEXTURE_2D, Font::getDefaultFont()->getTexture());
    191161  }
    192   const char* tmpText = this->externText;
    193   if (this->externText == NULL)
    194     tmpText = this->text;
    195   if (likely(tmpText != NULL))
     162  if (likely(!this->text.empty()))
    196163  {
    197164    glTranslatef(getAbsCoor2D().x, getAbsCoor2D().y, 0);
     
    201168
    202169    glBegin(GL_QUADS);
    203     while (likely(*tmpText != '\0'))
     170    for (unsigned int i = 0; i < this->text.size(); i++)
    204171    {
    205       if(likely((tmpGlyph = glyphArray[*tmpText]) != NULL))
     172      if(likely((tmpGlyph = glyphArray[this->text[i]]) != NULL))
    206173      {
    207174        glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]);
     
    219186        posX += tmpGlyph->advance * this->getSizeY2D();
    220187      }
    221       ++tmpText;
    222188    }
    223189    glEnd();
     
    232198void Text::debug() const
    233199{
    234   if (this->externText == NULL)
    235     PRINT(0)("=== TEXT: %s ===\n", this->text);
    236   else
    237     PRINT(0)("=== TEXT: %s ===\n", this->externText);
     200  PRINT(0)("=== TEXT: %s ===\n", this->text.c_str());
    238201
    239202  if (this->getBindNode())
  • trunk/src/lib/graphics/text_engine/text.h

    r6981 r7221  
    3939{
    4040  public:
    41     Text(const char* fontFile = NULL, unsigned int fontSize = TEXT_DEFAULT_SIZE);
     41    Text(const std::string& fontFile = "", unsigned int fontSize = TEXT_DEFAULT_SIZE);
    4242    virtual ~Text();
    4343    void init();
    4444
    45     void setFont(const char* fontFile, unsigned int renderSize);
     45    void setFont(const std::string& fontFile, unsigned int renderSize);
    4646
    47     void setText(const char* text, bool isExtern = false);
     47    void setText(const std::string& text);
    4848
    4949    /** @returns the String this Text displays */
    50     inline const char* getText() const { return (externText == NULL)?this->text:this->externText; };
     50    inline const std::string& getText() const { return this->text; };
    5151    /** @param blending the blending intensity to set (between 0.0 and 1.0) */
    5252    inline void setBlending(float blending) { this->blending = blending; };
     
    6969    Font*             font;           //!< Font of this text
    7070
    71     char*             text;           //!< The text to display
    72     const char*       externText;     //!< the text to Display from an external Source.
     71    std::string       text;           //!< The text to display
    7372    Vector            color;          //!< The color of the font.
    7473    float             blending;       //!< The blending intensity.
Note: See TracChangeset for help on using the changeset viewer.