Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7727 in orxonox.OLD for trunk/src/lib/graphics/importer


Ignore:
Timestamp:
May 19, 2006, 2:25:15 PM (18 years ago)
Author:
bensch
Message:

trunk: some GL-properties for the Textures

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

Legend:

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

    r7676 r7727  
    3030
    3131/**
    32  * Constructor for a Texture
     32 * @brief Constructor for a Texture
    3333*/
    3434Texture::Texture(const std::string& imageName, GLenum target)
     
    5050
    5151/**
    52  * Destructor of a Texture
    53 
    54    Frees Data, and deletes the textures from GL
    55 */
     52 * @brief Destructor of a Texture
     53 *
     54 * Frees Data, and deletes the textures from GL
     55 */
    5656Texture::~Texture()
    5757{
     
    6464
    6565/**
    66  * loads an Image from a file to a Texture
     66 * @brief loads an Image from a file to a Texture
    6767 * @param imageName The image to load
    6868*/
     
    121121
    122122/**
    123  * rebuilds the texture.
     123 * @brief rebuilds the texture.
     124 *
    124125 * reloads the Texture from Memory to OpenGL.
    125126 */
     
    142143
    143144/**
    144  * set the surface this Texture handles
     145 * @brief set the surface this Texture handles
    145146 * @param newSurface the new Surface to set as the image for this Texture.
    146147 *
     
    162163
    163164/**
    164  * enables, disables textures
     165 * @brief enables, disables textures
    165166 * @param texturesEnabled true if the textures should be enabled
    166167 */
     
    175176//////////////////////////////////////
    176177/**
    177  * converts surface to a new SDL_Surface, that is loadable by openGL
     178 * @brief converts surface to a new SDL_Surface, that is loadable by openGL
    178179 * @param surface the Surface to convert
    179180 * @param hasAlpha if the newly created Surface has an alpha channel, true is returned otherwise false.
     
    182183SDL_Surface* Texture::prepareSurface(SDL_Surface* surface, bool& hasAlpha) const
    183184{
     185  assert(surface != NULL);
    184186  PRINTF(4)("Loading texture to OpenGL-Environment.\n");
    185187
     
    190192
    191193  hasAlpha = false;
    192   retSurface = SDL_CreateRGBSurface(SDL_SWSURFACE,
     194  int pixelDepth = 24;
     195
     196  /* Save the alpha blending attributes */
     197  saved_flags = surface->flags&(SDL_SRCALPHA | SDL_RLEACCELOK);
     198  saved_alpha = surface->format->alpha;
     199  if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA )
     200  {
     201    SDL_SetAlpha(surface, 0, 0);
     202    hasAlpha = true;
     203    pixelDepth = 32;
     204  }
     205
     206  retSurface = SDL_CreateRGBSurface(SDL_HWSURFACE,
    193207                                    surface->w, surface->h,
    194                                     32,
     208                                    pixelDepth,
    195209#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
    196210                                    0x000000FF,
     
    206220                                   );
    207221  if ( retSurface == NULL )
    208   {
    209222    return NULL;
    210   }
    211 
    212   /* Save the alpha blending attributes */
    213   saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
    214   saved_alpha = surface->format->alpha;
    215   if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA )
    216   {
    217     SDL_SetAlpha(surface, 0, 0);
    218   }
    219223
    220224  /* Copy the surface into the GL texture image */
     
    237241
    238242/**
    239  * Loads a Texture to the openGL-environment.
     243 * @brief Loads a Texture to the openGL-environment.
    240244 * @param surface the Image to load to openGL
    241245 * @returns The ID of the texture.
     
    246250  //     glDeleteTextures(1, &this->texture);
    247251  //   this->texture = 0;
     252  assert(surface != NULL);
    248253
    249254  int      errorCode = 0;           //!< the error code for the texture loading functions
     
    252257  int      mipmapWidth = 0;         //!< the width of the mipmap
    253258  int      mipmapHight = 0;         //!< the height of the mipmap
    254 
    255 
    256   if (surface == NULL)
    257     return 0;
     259  GLenum   format = GL_RGB;
     260  if (this->bAlpha)
     261  {
     262    format = GL_RGBA;
     263    assert(surface->format->BitsPerPixel == 32);
     264  }
     265  else
     266  {
     267    assert(surface->format->BitsPerPixel == 24);
     268  }
    258269
    259270  /* Create an OpenGL texture for the image */
     
    261272  glBindTexture(target, texture);
    262273
     274//   glTexImage2D(target,  0,  format,
     275//                surface->w,  surface->h,
     276//                0, format,  GL_UNSIGNED_BYTE,
     277//                surface->pixels);
     278
    263279  glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT);
    264280  glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_REPEAT);
     
    275291
    276292  /* build the Texture  OpenGL V >= 1.1 */
    277   glTexImage2D(target,
    278                0,
    279                GL_RGBA,
    280                surface->w,
    281                surface->h,
    282                0,
    283                GL_RGBA,
    284                GL_UNSIGNED_BYTE,
    285                surface->pixels);
     293
    286294  //  printf("%s, w:%d h:%d, 0x%x\n", this->getName(), surface->w, surface->h, target);
    287295
    288296  // build the MipMaps automaticaly
    289   errorCode = gluBuild2DMipmaps(target,
    290                                 GL_RGBA,
    291                                 surface->w,
    292                                 surface->h,
    293                                 GL_RGBA,
    294                                 GL_UNSIGNED_BYTE,
     297  errorCode = gluBuild2DMipmaps(target, format,
     298                                surface->w,  surface->h,
     299                                format,  GL_UNSIGNED_BYTE,
    295300                                surface->pixels
    296301                               );
  • trunk/src/lib/graphics/importer/texture.h

    r7221 r7727  
    4343
    4444    protected:
    45 
    4645      bool setSurface(SDL_Surface* newSurface);
    4746      bool setAlpha(bool hasAlpha) { this->bAlpha = hasAlpha; };
    4847      bool setTexture(GLuint texture) { this->texture = texture; };
    49 
    5048
    5149    private:
Note: See TracChangeset for help on using the changeset viewer.