Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5863 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Dec 1, 2005, 9:14:30 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: TextureSequence finished for testing

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

Legend:

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

    r5860 r5863  
    4545}
    4646
     47
    4748/**
    4849 *  Destructor of a Texture
     
    5758    SDL_FreeSurface(this->image);
    5859}
     60
    5961
    6062/**
     
    114116}
    115117
     118
     119/**
     120 * rebuilds the texture.
     121 * reloads the Texture from Memory to OpenGL.
     122 */
    116123bool Texture::rebuild()
    117124{
     
    128135      this->setTexture(loadTexToGL(this->image));
    129136    }
    130 
    131 }
    132 
     137}
     138
     139
     140/**
     141 * set the surface this Texture handles
     142 * @param newSurface the new Surface to set as the image for this Texture.
     143 *
     144 * This deletes the old version of the stored Texture,
     145 * and sets the newly given Surface as current.
     146 */
     147bool Texture::setSurface(SDL_Surface* newSurface)
     148{
     149  if (this->image != NULL)
     150    SDL_FreeSurface(this->image);
     151
     152  this->image = newSurface;
     153
     154  return (this->image != NULL);
     155}
     156
     157
     158bool Texture::texturesEnabled = true;
     159
     160/**
     161 * enables, disables textures
     162 * @param texturesEnabled true if the textures should be enabled
     163 */
     164void Texture::setTextureEnableState(bool texturesEnabled)
     165{
     166  Texture::texturesEnabled = texturesEnabled;
     167}
     168
     169
     170//////////////////////////////////////
     171// UTILITY FUNCTIONALITY OF TEXTURE //
     172//////////////////////////////////////
    133173/**
    134174 * converts surface to a new SDL_Surface, that is loadable by openGL
     
    148188  hasAlpha = false;
    149189  retSurface = SDL_CreateRGBSurface(SDL_SWSURFACE,
    150                                surface->w, surface->h,
    151                                32,
     190                                    surface->w, surface->h,
     191                                    32,
    152192#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
    153193                               0x000000FF,
     
    156196                               0xFF000000
    157197#else
    158                                0xFF000000,
     198                                   0xFF000000,
    159199                               0x00FF0000,
    160200                               0x0000FF00,
    161201                               0x000000FF
    162202#endif
    163                                );
     203                                   );
    164204  if ( retSurface == NULL )
    165205  {
     
    191231}
    192232
    193 /**
    194  * set the surface this Texture handles
    195  * @param newSurface the new Surface to set as the image for this Texture.
    196  *
    197  * This deletes the old version of the stored Texture,
    198  * and sets the newly given Surface as current.
    199  */
    200 bool Texture::setSurface(SDL_Surface* newSurface)
    201 {
    202   if (this->image != NULL)
    203     SDL_FreeSurface(this->image);
    204 
    205   this->image = newSurface;
    206 
    207   return (this->image != NULL);
    208 }
    209 
    210 
    211 bool Texture::texturesEnabled = true;
    212 
    213 /**
    214  * enables, disables textures
    215  * @param texturesEnabled true if the textures should be enabled
    216  */
    217 void Texture::setTextureEnableState(bool texturesEnabled)
    218 {
    219   Texture::texturesEnabled = texturesEnabled;
    220 }
    221 
    222 
    223 //////////////////////////////////////
    224 // UTILITY FUNCTIONALITY OF TEXTURE //
    225 //////////////////////////////////////
     233
    226234/**
    227235 *  Loads a Texture to the openGL-environment.
  • trunk/src/lib/graphics/importer/texture_sequence.cc

    r5861 r5863  
    2020#include "debug.h"
    2121#include "graphics_engine.h"
    22 
    23 #include <stdarg.h>
    2422
    2523#ifdef HAVE_SDL_IMAGE_H
     
    4947TextureSequence::~TextureSequence()
    5048{
     49  // delete all images
     50  while(!this->images.empty())
     51  {
     52    SDL_FreeSurface(this->images.back());
     53    this->images.pop_back();
     54  }
     55
     56  // delete all textures.
     57  while(!this->textures.empty())
     58  {
     59    if (glIsTexture(this->textures.back()))
     60      glDeleteTextures(1, &this->textures.back());
     61    this->textures.pop_back();
     62  }
    5163}
    5264
     
    5769bool TextureSequence::rebuild()
    5870{
    59 //   if (this->texture != 0 && glIsTextureSequence(this->texture))
    60 //     {
    61 //       glDeleteTextureSequences(1,&this->texture);
    62 //       this->texture = 0;
    63 //     }
    64 //
    65 //   if (this->image != NULL)
    66 //     {
    67 //       PRINTF(3)("Reloading TextureSequence of %s '%s'\n", this->getClassName(), this->getName());
    68 //       this->texture = loadTexToGL(this->image);
    69 //     }
     71  PRINTF(3)("Reloading TextureSequence of %s '%s'\n", this->getClassName(), this->getName());
    7072
     73  for (unsigned int i = 0; i < this->textures.size(); i++)
     74  {
     75    if (glIsTexture(this->textures[i]))
     76    {
     77      glDeleteTextures(1, &this->textures[i]);
     78      this->textures[i] = 0;
     79    }
     80
     81    if (this->images[i] != NULL)
     82      this->textures[i] = loadTexToGL(this->images[i]);
     83  }
    7184}
    7285
    73 
    74 
     86/**
     87 * loads an image Series
     88 * @param count how many images to load to the TextureSequence
     89 * @param ... the names of the Images to load
     90 * @returns true on success, false otherwise
     91 */
    7592bool TextureSequence::loadImageSeries(unsigned int count, ...)
    7693{
     
    7895  va_start(textureNameList, count);
    7996
    80   this->loadImageSeries(count, textureNameList);
     97  return this->loadImageSeries(count, textureNameList);
    8198}
    8299
     100/**
     101 * loads an image Series
     102 * @param count how many images to load to the TextureSequence
     103 * @param textures the names of the Images to load
     104 * @returns true on success, false otherwise
     105 */
    83106bool TextureSequence::loadImageSeries(unsigned int count, va_list textures)
    84107{
    85 
    86 
     108  bool retVal = true;
     109  for (unsigned int i = 0; i < count; i++)
     110  {
     111    if( !this->addFrame(va_arg(textures, char*)))
     112      retVal = false;
     113  }
     114  return retVal;
    87115}
    88116
     
    90118bool TextureSequence::addFrame(const char* imageName)
    91119{
     120  if (imageName == NULL)
     121    return false;
    92122
     123  SDL_Surface* addSurface = IMG_Load(imageName);
     124  bool success = this->addFrame(addSurface);
     125  delete addSurface;
    93126
     127  return success;
    94128}
    95129
    96 
     130/**
     131 * adds a new Frame at the end of the Sequence.
     132 * @param surface the Surface to add at the end of the Sequence.
     133 */
    97134bool TextureSequence::addFrame(SDL_Surface* surface)
    98135{
    99 
    100 
     136  if (surface == NULL)
     137    return false;
     138  bool hasAlpha;
     139  SDL_Surface* newSurf = this->prepareSurface(surface, hasAlpha);
     140  if (newSurf != NULL)
     141  {
     142    this->images.push_back(newSurf);
     143    this->textures.push_back(Texture::loadTexToGL(newSurf));
     144  }
     145  this->setAlpha(hasAlpha);
    101146}
    102 
    103 
Note: See TracChangeset for help on using the changeset viewer.