Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Jun 14, 2006, 10:37:08 AM (18 years ago)
Author:
bensch
Message:

trunk: splitted Texture and TextureData into two files.
Also fixed the Creator-Function for Textures with empty textures with size

File:
1 edited

Legend:

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

    r8316 r8363  
    3737 */
    3838Uint32 alphaMask[] = {
    39         0xFF000000,
    40         0x00FF0000,
    41         0x0000FF00,
    42         0x000000FF,
    43 };
     39                       0xFF000000,
     40                       0x00FF0000,
     41                       0x0000FF00,
     42                       0x000000FF,
     43                     };
    4444
    4545Uint32 opaqueMask[] = {
    46         0x00FF0000,
    47         0x0000FF00,
    48         0x000000FF,
    49         0xFF000000
    50 };
     46                        0x00FF0000,
     47                        0x0000FF00,
     48                        0x000000FF,
     49                        0xFF000000
     50                      };
    5151#else
    5252/*
    53  * On the LIL_ENDIAN architecture everything is fine and easy. The 24
    54  * and 32bit bitmaps have the same masks.
    55  */
     53* On the LIL_ENDIAN architecture everything is fine and easy. The 24
     54* and 32bit bitmaps have the same masks.
     55*/
    5656Uint32 alphaMask[] = {
    57         0x000000FF,
    58         0x0000FF00,
    59         0x00FF0000,
    60         0xFF000000,
    61 };
     57                       0x000000FF,
     58                       0x0000FF00,
     59                       0x00FF0000,
     60                       0xFF000000,
     61                     };
    6262
    6363Uint32 *opaqueMask = alphaMask;
    64 
    6564#endif
    6665
    67 TextureData::TextureData()
    68 {
    69   this->bAlpha = false;
    70   this->texture = 0;
    71   this->image = NULL;
    72 }
    73 
    74 
    75 /**
    76  * @brief Destructor of a Texture
     66
     67
     68/**
     69 * @brief creates an Empty Texture,
    7770 *
    78  *  Frees Data, and deletes the textures from GL
    79  */
    80 TextureData::~TextureData()
    81 {
    82   if (this->texture != 0)
    83     glDeleteTextures(1, &this->texture);
    84   if (this->image != NULL)
    85     SDL_FreeSurface(this->image);
    86 }
    87 
    88 
    89 /**
    90  * @brief Loads an SDL_Surface.
    91  */
    92 bool TextureData::loadSurface(SDL_Surface* surface, GLenum target)
    93 {
    94   if (Texture::getTextureEnableState())
    95   {
    96     SDL_Surface* newSurf = Texture::prepareSurface(surface, this->bAlpha);
    97     if (newSurf != NULL)
    98     {
    99       this->setSurface(newSurf);
    100       this->setTexture(Texture::loadTexToGL(newSurf, target));
    101       return true;
    102     }
    103   }
    104   return false;
    105 }
    106 
    107 
    108 
    109 /**
    110  * @brief set the surface this Texture handles
    111  * @param newSurface the new Surface to set as the image for this Texture.
     71 * onto this Texture you can load non-empty textures with the =
     72 * operator.
     73 */
     74Texture::Texture()
     75{
     76  this->init();
     77}
     78
     79/**
     80 * @brief Creates a Texture from another Texture (copy Constructor)
     81 * @param texture the Texture to copy.
    11282 *
    113  * This deletes the old version of the stored Texture,
    114  * and sets the newly given Surface as current.
    115  */
    116 bool TextureData::setSurface(SDL_Surface* newSurface)
    117 {
    118   if (this->image != NULL)
    119     SDL_FreeSurface(this->image);
    120 
    121   this->image = newSurface;
    122 
    123   return (this->image != NULL);
    124 }
    125 
    126 
    127 
    128 bool TextureData::setTexture(GLuint texture)
    129 {
    130      // unload the old Texture.
    131   if (this->texture != 0 && glIsTexture(this->getTexture()))
    132   {
    133     glDeleteTextures(1, &this->texture);
    134   }
    135   this->texture = texture;
    136   return (texture != 0);
    137 }
    138 
    139 Texture::Texture()
    140 {
    141   this->init();
    142 }
    143 
    144 
     83 * @note only the Data-Pointer will be shared.
     84 */
    14585Texture::Texture(const Texture& texture)
    146   : data(texture.data)
     86    : data(texture.data)
    14787{
    14888  this->setClassID(CL_TEXTURE, "Texture");
     
    15090}
    15191
    152 
     92/**
     93 * @brief Creates a new empty Texture with the below properties.
     94 * @param target: the GL-Target.
     95 * @param width: the Width of the Texture.
     96 * @param height: The Hight of the Texture.
     97 * @param channels: also known as BitsPerPixel.
     98 * @param type the Type of Texture.
     99 */
    153100Texture::Texture(GLenum target, unsigned int width, unsigned int height, unsigned int channels, GLenum type)
    154101{
    155102  this->init();
    156   GLuint texture = 0;
    157   Texture::generateTexture(texture, target);
    158 
    159   glBindTexture(target, texture);
    160 
    161   unsigned int* pixels = new unsigned int[width * height * channels];
    162   memset(pixels, 0, width * height * channels * sizeof(unsigned int));
    163 
    164 
    165   glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    166   glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    167   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    168   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    169 
    170   glTexImage2D(target, 0, channels, width, height, 0, type, GL_UNSIGNED_INT, pixels);
    171 
    172 
    173 
    174   delete[] pixels;
    175 
    176   this->data->setTexture(texture);
     103
     104  SDL_Surface * surface = SDL_CreateRGBSurface(SDL_HWSURFACE, width, height, channels,
     105                          alphaMask[0], alphaMask[1], alphaMask[2], alphaMask[3]);
     106
     107  if(surface != NULL)
     108  {
     109    this->data->loadSurface(surface, target);
     110    SDL_FreeSurface(surface);
     111  }
    177112}
    178113
     
    218153 */
    219154Texture::~Texture()
    220 {
    221 }
     155{}
    222156
    223157
     
    308242  int pixelDepth = 24;
    309243
    310         Uint32* mask = opaqueMask;
     244  Uint32* mask = opaqueMask;
    311245
    312246  /* Save the alpha blending attributes */
     
    318252    hasAlpha = true;
    319253    pixelDepth = 32;
    320                 mask = alphaMask;
     254    mask = alphaMask;
    321255  }
    322256
     
    324258                                    surface->w, surface->h,
    325259                                    pixelDepth,
    326                                                                                                                                                 mask[0], mask[1], mask[2], mask[3] );
     260                                    mask[0], mask[1], mask[2], mask[3] );
    327261  if ( retSurface == NULL )
    328262    return NULL;
     
    377311  Texture::generateTexture(texture, target);
    378312
    379 //   glTexImage2D(target,  0,  format,
    380 //                surface->w,  surface->h,
    381 //                0, format,  GL_UNSIGNED_BYTE,
    382 //                surface->pixels);
    383 
    384 ///  glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT);
    385 ///  glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT);
     313  //   glTexImage2D(target,  0,  format,
     314  //                surface->w,  surface->h,
     315  //                0, format,  GL_UNSIGNED_BYTE,
     316  //                surface->pixels);
     317
     318  ///  glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT);
     319  ///  glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT);
    386320
    387321  /// TODO CHECK THIS BACK in
Note: See TracChangeset for help on using the changeset viewer.