Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 18, 2006, 3:16:46 PM (19 years ago)
Author:
stefalie
Message:

branches/water: activate/deactivate reflection/refraction functions added

File:
1 edited

Legend:

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

    r7221 r7687  
    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  }
     
    264293  glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT);
    265294
    266   glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR/*_MIPMAP_LINEAR*/);
     295  glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    267296  glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    268297
Note: See TracChangeset for help on using the changeset viewer.