Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
May 24, 2006, 3:41:09 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: Material handles references… lets see if this works

Location:
trunk/src/lib/graphics/importer
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/importer/material.cc

    r7785 r7788  
    2222#include "debug.h"
    2323#include "util/loading/resource_manager.h"
    24 #include <stdlib.h>
    25 #include <string.h>
    26 
    27 //! @todo check if we are in RESOURCE MANAGER-mode
    28 #include "util/loading/resource_manager.h"
    29 
    30 using namespace std;
    31 
    32 /**
    33  * creates a Material.
     24
     25/**
     26 * @brief creates a Material.
    3427 * @param mtlName Name of the Material to be added to the Material List
    3528 */
     
    5447
    5548/**
    56   * deletes a Material
    57 */
     49 * @brief deletes a Material
     50 */
    5851Material::~Material()
    5952{
    6053  PRINTF(5)("delete Material %s.\n", this->getName());
    61 
    62   while(!this->textures.empty())
    63   {
    64     if (this->textures.back() != NULL)
    65       ResourceManager::getInstance()->unload(this->textures.back());
    66     this->textures.pop_back();
    67   }
    6854
    6955  if (this->ambientTexture != NULL)
     
    115101
    116102/**
    117  * sets the material with which the following Faces will be painted
     103 * @brief sets the material with which the following Faces will be painted
    118104 */
    119105bool Material::select() const
     
    135121  // setting the transparency
    136122  if (this->transparency < 1.0 ||       /* This allows alpha blending of 2D textures with the scene */
    137       (likely(!this->textures.empty() && this->textures[0] != NULL) && this->textures[0]->hasAlpha()))
     123      (likely(!this->textures.empty() && this->textures[0].hasAlpha())))
    138124  {
    139125    glEnable(GL_BLEND);
     
    164150  for(unsigned int i = 0; i < this->textures.size(); ++i)
    165151  {
    166     if (likely(this->textures[i] != NULL))
    167     {
    168152      glActiveTexture(Material::glTextureArbs[i]);
    169153      glEnable(GL_TEXTURE_2D);
    170       if(this->textures[i]->hasAlpha())
     154      if(this->textures[i].hasAlpha())
    171155      {
    172156        glEnable(GL_BLEND);
    173157      }
    174       glBindTexture(GL_TEXTURE_2D, this->textures[i]->getTexture());
    175     }
     158      glBindTexture(GL_TEXTURE_2D, this->textures[i].getTexture());
    176159  }
    177160  Material::selectedMaterial = this;
     
    333316// MAPPING //
    334317
    335 void Material::setDiffuseMap(Texture* texture, unsigned int textureNumber)
     318void Material::setDiffuseMap(const Texture& texture, unsigned int textureNumber)
    336319{
    337320  assert(textureNumber < Material::getMaxTextureUnits());
    338321
    339   if (this->textures.size() > textureNumber && this->textures[textureNumber] != NULL)
    340     ResourceManager::getInstance()->unload(this->textures[textureNumber]);
    341 
    342322  if (this->textures.size() <= textureNumber)
    343     this->textures.resize(textureNumber+1, NULL);
     323    this->textures.resize(textureNumber+1, Texture());
    344324
    345325  //! @todo check if RESOURCE MANAGER is availiable
     
    357337
    358338  PRINTF(5)("setting Diffuse Map %s\n", dMap.c_str());
    359   if (this->textures.size() > textureNumber && this->textures[textureNumber] != NULL)
    360     ResourceManager::getInstance()->unload(this->textures[textureNumber]);
    361 
    362339  if (this->textures.size() <= textureNumber)
    363     this->textures.resize(textureNumber+1, NULL);
     340    this->textures.resize(textureNumber+1, Texture());
    364341
    365342  //! @todo check if RESOURCE MANAGER is availiable
     
    367344  {
    368345
    369     this->textures[textureNumber] = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target);
     346    this->textures[textureNumber] = *(Texture*)ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target);
    370347  }
    371348  else
    372349  {
    373     this->textures[textureNumber] = NULL;
    374   }
    375 }
    376 
    377 /**
    378  * Sets the Materials Diffuse Map
     350    this->textures[textureNumber] = Texture();
     351  }
     352}
     353
     354/**
     355 * @brief Sets the Materials Diffuse Map
    379356 * @param surface pointer to SDL_Surface which shall be used as texture
    380357*/
     
    384361
    385362
    386   if (this->textures.size() > textureNumber && this->textures[textureNumber] != NULL)
    387     ResourceManager::getInstance()->unload(this->textures[textureNumber]);
    388 
    389363  if (this->textures.size() <= textureNumber)
    390     this->textures.resize(textureNumber+1, NULL);
     364    this->textures.resize(textureNumber+1, Texture());
    391365
    392366  if(surface != NULL)
    393367  {
    394     this->textures[textureNumber] = new Texture(surface, GL_TEXTURE_2D);
     368    this->textures[textureNumber] = Texture(surface, GL_TEXTURE_2D);
    395369  }
    396370  else
    397371  {
    398     this->textures[textureNumber] = NULL;
    399   }
    400 
    401 }
    402 
    403 
    404 /**
    405  * Sets the Materials Ambient Map
     372    this->textures[textureNumber] = Texture();
     373  }
     374
     375}
     376
     377
     378/**
     379 * @brief Sets the Materials Ambient Map
    406380 * @param aMap the Name of the Image to Use
    407381   @todo implement this
     
    414388
    415389/**
    416  * Sets the Materials Specular Map
     390 * @brief Sets the Materials Specular Map
    417391 * @param sMap the Name of the Image to Use
    418392   @todo implement this
     
    425399
    426400/**
    427  * Sets the Materials Bumpiness
     401 * @brief Sets the Materials Bumpiness
    428402 * @param bump the Name of the Image to Use
    429    @todo implemet this
     403 * @todo implemet this
    430404*/
    431405void Material::setBump(const std::string& bump)
  • trunk/src/lib/graphics/importer/material.h

    r7785 r7788  
    5353
    5454    // MAPPING //
    55     void setDiffuseMap(Texture* texture, unsigned int textureNumber = 0);
     55    void setDiffuseMap(const Texture& texture, unsigned int textureNumber = 0);
    5656    void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0);
    5757    void setSDLDiffuseMap(SDL_Surface *surface, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0);
     
    6060    void setSpecularMap(const std::string& sMap, GLenum target = GL_TEXTURE_2D);
    6161    void setBump(const std::string& bump);
    62     GLuint getDiffuseTexture(unsigned int i = 0) const { return (this->textures.size() > i)? this->textures[i]->getTexture() : 0; };
     62    GLuint getDiffuseTexture(unsigned int i = 0) const { return (this->textures.size() > i)? this->textures[i].getTexture() : 0; };
    6363
    6464    static void addTexturePath(const std::string& pathName);
     
    8181    GLenum           tFactor;
    8282
    83     std::vector<Texture*> textures;    //!< An Array of Textures.
     83    std::vector<Texture> textures;    //!< An Array of Textures.
    8484
    8585    Texture*         ambientTexture;   //!< The ambient texture of the Material.
  • trunk/src/lib/graphics/importer/texture.cc

    r7785 r7788  
    103103
    104104
     105Texture::Texture(const Texture& texture)
     106  : data(texture.data)
     107{
     108  this->setClassID(CL_TEXTURE, "Texture");
     109  this->priority = 0.5;
     110}
    105111
    106112
  • trunk/src/lib/graphics/importer/texture.h

    r7785 r7788  
    3030    bool loadSurface(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D);
    3131
    32 
    33 
    3432    bool rebuild();
    3533
    3634    bool setSurface(SDL_Surface* newSurface);
     35    /** @returns true if the Surface has an Alpha Value. */
    3736    bool setAlpha(bool hasAlpha) { this->bAlpha = hasAlpha; };
    3837    bool setTexture(GLuint texture);
     
    4948{
    5049public:
    51 
    52 public:
     50  Texture(const Texture& texture);
    5351  Texture(GLenum target = GL_TEXTURE_2D);
    5452  Texture(const std::string& imageName, GLenum target = GL_TEXTURE_2D);
Note: See TracChangeset for help on using the changeset viewer.