Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5859 in orxonox.OLD for trunk/src/lib/graphics/importer/texture.cc


Ignore:
Timestamp:
Dec 1, 2005, 8:19:26 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: small changes in the Texture interface

File:
1 edited

Legend:

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

    r5858 r5859  
    8686          {
    8787            PRINTF(4)("loading Image %s\n", imageName);
    88             if (this->prepareSurface(tmpSurf))
    89               this->texture = Texture::loadTexToGL(this->image);
     88            bool hasAlpha;
     89            SDL_Surface* newSurf = this->prepareSurface(tmpSurf, hasAlpha);
     90            if (newSurf != NULL)
     91            {
     92              this->setSurface(newSurf);
     93              this->setAlpha(hasAlpha);
     94              this->setTexture(Texture::loadTexToGL(newSurf));
     95            }
    9096
    9197            SDL_FreeSurface(tmpSurf);
     
    113119    {
    114120      glDeleteTextures(1,&this->texture);
    115       this->texture = 0;
     121      this->setTexture(0);
    116122    }
    117123
     
    119125    {
    120126      PRINTF(3)("Reloading Texture of %s '%s'\n", this->getClassName(), this->getName());
    121       this->texture = loadTexToGL(this->image);
     127      this->setTexture(loadTexToGL(this->image));
    122128    }
    123129
     
    127133 * converts surface to a new SDL_Surface, that is loadable by openGL
    128134 * @param surface the Surface to convert
     135 * @param hasAlpha if the newly created Surface has an alpha channel, true is returned otherwise false.
    129136 * @returns a !!new!! Surface, that is loadable by openGL.
    130137 */
    131 bool Texture::prepareSurface(SDL_Surface* surface)
     138SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha)
    132139{
    133140  PRINTF(4)("Loading texture to OpenGL-Environment.\n");
    134141
    135   SDL_Surface* putSurface;
     142  SDL_Surface* retSurface;
    136143  SDL_Rect area;
    137144  Uint32 saved_flags;
    138145  Uint8  saved_alpha;
    139146
    140   putSurface = SDL_CreateRGBSurface(SDL_SWSURFACE,
     147  hasAlpha = false;
     148  retSurface = SDL_CreateRGBSurface(SDL_SWSURFACE,
    141149                               surface->w, surface->h,
    142150                               32,
     
    153161#endif
    154162                               );
    155   if ( putSurface == NULL )
     163  if ( retSurface == NULL )
    156164  {
    157     this->setSurface(NULL);
    158     return false;
     165    return NULL;
    159166  }
    160167
     
    171178  area.w = surface->w;
    172179  area.h = surface->h;
    173   SDL_BlitSurface(surface, &area, putSurface, &area);
     180  SDL_BlitSurface(surface, &area, retSurface, &area);
    174181
    175182  /* Restore the alpha blending attributes */
     
    177184  {
    178185    SDL_SetAlpha(surface, saved_flags | SDL_OPENGL, saved_alpha);
    179     this->bAlpha = true;
    180   }
    181 
    182   return (this->setSurface(putSurface));
    183 }
    184 
     186    hasAlpha = true;
     187  }
     188
     189  return (retSurface);
     190}
     191
     192/**
     193 * set the surface this Texture handles
     194 * @param newSurface the new Surface to set as the image for this Texture.
     195 *
     196 * This deletes the old version of the stored Texture,
     197 * and sets the newly given Surface as current.
     198 */
    185199bool Texture::setSurface(SDL_Surface* newSurface)
    186200{
Note: See TracChangeset for help on using the changeset viewer.