Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7522 in orxonox.OLD


Ignore:
Timestamp:
May 3, 2006, 4:42:35 PM (18 years ago)
Author:
bensch
Message:

Textures are way improved now

Location:
branches/bsp_model/src/lib/graphics/importer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/bsp_model/src/lib/graphics/importer/texture.cc

    r7465 r7522  
    3434Texture::Texture(const std::string& imageName, GLenum target)
    3535{
     36  this->init();
     37
     38  if (!imageName.empty())
     39  {
     40    this->setName(imageName);
     41    this->loadImage(imageName, target);
     42  }
     43}
     44
     45Texture::Texture(SDL_Surface* surface, GLenum target)
     46{
     47  this->init();
     48
     49  if(surface != NULL)
     50  {
     51    this->loadSurface(surface, target);
     52
     53  }
     54}
     55
     56void Texture::init()
     57{
    3658  this->setClassID(CL_TEXTURE, "Texture");
    3759
     
    4062  this->image = NULL;
    4163  this->priority = 0.5;
    42 
    43   if (!imageName.empty())
    44   {
    45     this->setName(imageName);
    46     this->loadImage(imageName, target);
    47   }
    48 }
    49 
     64}
    5065
    5166/**
     
    6479
    6580/**
    66  * loads an Image from a file to a Texture
     81 * @brief loads an Image from a file to a Texture
    6782 * @param imageName The image to load
    6883*/
     
    7186  if (Texture::texturesEnabled)
    7287  {
    73     if (this->image != NULL)
    74     {
    75       SDL_FreeSurface(this->image);
    76       this->image = NULL;
    77     }
    78     if (this->texture != 0)
    79     {
    80       glDeleteTextures(1, &this->texture);
    81       this->texture = 0;
    82     }
    8388    if (!imageName.empty())
    8489    {
    8590      SDL_Surface* tmpSurf;
    86       if (this->texture != 0 && glIsTexture(this->texture))
    87         glDeleteTextures(1, &this->texture);
     91
    8892      // load the new Image to memory
    8993      tmpSurf = IMG_Load(imageName.c_str());
    9094      if(tmpSurf != NULL)
    9195      {
    92         PRINTF(4)("loading Image %s\n", imageName);
    93         bool hasAlpha;
    94         SDL_Surface* newSurf = this->prepareSurface(tmpSurf, hasAlpha);
    95         if (newSurf != NULL)
    96         {
    97           this->setSurface(newSurf);
    98           this->setAlpha(hasAlpha);
    99           this->setTexture(Texture::loadTexToGL(newSurf, target));
    100         }
    101 
     96        this->loadSurface(tmpSurf, target);
    10297        SDL_FreeSurface(tmpSurf);
    10398        return true;
     
    114109      PRINTF(2)("Image-Name not specified\n");
    115110      return false;
     111    }
     112  }
     113  return false;
     114}
     115
     116/**
     117 * @brief Loads an SDL_Surface.
     118 */
     119bool Texture::loadSurface(SDL_Surface* surface, GLenum target)
     120{
     121  if (Texture::texturesEnabled)
     122  {
     123    // some image was loaded before
     124    if (this->image != NULL)
     125    {
     126      SDL_FreeSurface(this->image);
     127      this->image = NULL;
     128    }
     129
     130    // unload the old Texture.
     131    if (this->texture != 0 && glIsTexture(this->texture))
     132    {
     133      glDeleteTextures(1, &this->texture);
     134      this->texture = 0;
     135    }
     136
     137    bool hasAlpha;
     138    SDL_Surface* newSurf = this->prepareSurface(surface, hasAlpha);
     139    if (newSurf != NULL)
     140    {
     141      this->setSurface(newSurf);
     142      this->setAlpha(hasAlpha);
     143      this->setTexture(Texture::loadTexToGL(newSurf, target));
     144      return true;
    116145    }
    117146  }
  • branches/bsp_model/src/lib/graphics/importer/texture.h

    r7221 r7522  
    1919    public:
    2020      Texture(const std::string& imageName = "", GLenum target = GL_TEXTURE_2D);
    21   //  Texture(TEXTURE_TYPE type, int resolution);
     21      Texture(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D);
    2222      virtual ~Texture();
    2323
    2424      bool loadImage(const std::string& imageName, GLenum target = GL_TEXTURE_2D);
     25      bool loadSurface(SDL_Surface* surface, GLenum target = GL_TEXTURE_2D);
    2526      virtual bool rebuild();
    2627
     
    2829      inline GLuint getTexture() const { return this->texture; };
    2930      /** @returns true if texture has alpha, false otherwise */
    30       inline bool hasAlpha() const {return bAlpha;}
     31      inline bool hasAlpha() const  {return bAlpha; }
    3132      /** @returns the stored image of this Texture */
    3233      const SDL_Surface* const getStoredImage() const { return this->image; };
     
    4344
    4445    protected:
    45 
    4646      bool setSurface(SDL_Surface* newSurface);
    4747      bool setAlpha(bool hasAlpha) { this->bAlpha = hasAlpha; };
    4848      bool setTexture(GLuint texture) { this->texture = texture; };
    4949
     50    private:
     51      void init();
    5052
    5153    private:
Note: See TracChangeset for help on using the changeset viewer.