Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5859 in orxonox.OLD for trunk/src


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

orxonox/trunk: small changes in the Texture interface

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

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/importer/multi_frame_texture.h

    r5858 r5859  
    2727
    2828      /** @returns The textureID of this texture.  */
    29       inline GLuint getFrameTexture(unsigned int frameNumber);// const { return this->textures; };
     29      inline GLuint getFrameTexture(unsigned int frameNumber) const { return this->textures[frameNumber]; };
    3030
    31       const SDL_Surface* const getFrameImage() const { };
     31      const SDL_Surface* const getFrameImage(unsigned int frameNumber) const { return this->images[frameNumber]; };
    3232
    3333    private:
  • 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{
  • trunk/src/lib/graphics/importer/texture.h

    r5858 r5859  
    3939
    4040      // Utility functionality:
     41      static SDL_Surface* prepareSurface(SDL_Surface* input, bool& hasAlpha);
    4142      static GLuint loadTexToGL (const SDL_Surface* surface);
    4243
    4344    protected:
    44       bool prepareSurface(SDL_Surface* input);
     45
    4546      bool setSurface(SDL_Surface* newSurface);
     47      bool setAlpha(bool hasAlpha) { this->bAlpha = hasAlpha; };
    4648      bool setTexture(GLuint texture) { this->texture = texture; };
    4749
  • trunk/src/lib/graphics/text_engine/font.cc

    r5856 r5859  
    181181    this->fontTTF = NULL;
    182182  }
    183   if (this->prepareSurface(surface))
    184   {
    185     this->setTexture(Texture::loadTexToGL(this->getStoredImage()));
     183  bool hasAlpha;
     184  SDL_Surface* newSurf = this->prepareSurface(surface, hasAlpha);
     185  if (newSurf != NULL)
     186  {
     187    this->setSurface(newSurf);
     188    this->setAlpha(hasAlpha);
     189    this->setTexture(Texture::loadTexToGL(newSurf));
    186190  }
    187191
Note: See TracChangeset for help on using the changeset viewer.