Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 23, 2005, 2:09:07 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: safer compile support

File:
1 edited

Legend:

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

    r4370 r4662  
    1 /* 
     1/*
    22   orxonox - the future of 3D-vertical-scrollers
    33
     
    2121#include "graphics_engine.h"
    2222
     23#ifdef HAVE_SDL_IMAGE_H
    2324#include <SDL_image.h>
     25#else
     26#include <SDL/SDL_image.h>
     27#endif
    2428
    2529/**
     
    3236  if (imageName)
    3337    this->loadImage(imageName);
    34 } 
     38}
    3539
    3640/**
    3741   \brief Destructor of a Texture
    38    
     42
    3943   Frees Data, and deletes the textures from GL
    4044*/
     
    6266      Uint32 saved_flags;
    6367      Uint8  saved_alpha;
    64      
     68
    6569      w = surface->w;
    6670      h = surface->h;
    67      
     71
    6872      image = SDL_CreateRGBSurface(SDL_SWSURFACE,
    69                                    w, h,
    70                                    32,
     73                                   w, h,
     74                                   32,
    7175#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
    72                                    0x000000FF,
    73                                    0x0000FF00,
    74                                    0x00FF0000,
    75                                    0xFF000000
     76                                   0x000000FF,
     77                                   0x0000FF00,
     78                                   0x00FF0000,
     79                                   0xFF000000
    7680#else
    77                                    0xFF000000,
    78                                    0x00FF0000,
    79                                    0x0000FF00,
    80                                    0x000000FF
     81                                   0xFF000000,
     82                                   0x00FF0000,
     83                                   0x0000FF00,
     84                                   0x000000FF
    8185#endif
    82                                    );
     86                                   );
    8387      if ( image == NULL ) {
    84         return 0;
     88        return 0;
    8589      }
    86      
     90
    8791      /* Save the alpha blending attributes */
    8892      saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
    8993      saved_alpha = surface->format->alpha;
    9094      if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
    91         SDL_SetAlpha(surface, 0, 0);
     95        SDL_SetAlpha(surface, 0, 0);
    9296      }
    93      
     97
    9498      /* Copy the surface into the GL texture image */
    9599      area.x = 0;
     
    98102      area.h = surface->h;
    99103      SDL_BlitSurface(surface, &area, image, &area);
    100      
     104
    101105      /* Restore the alpha blending attributes */
    102106      if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
    103         SDL_SetAlpha(surface, saved_flags | SDL_OPENGL, saved_alpha);
    104         this->bAlpha = true;
     107        SDL_SetAlpha(surface, saved_flags | SDL_OPENGL, saved_alpha);
     108        this->bAlpha = true;
    105109      }
    106      
     110
    107111      /* Create an OpenGL texture for the image */
    108112      glGenTextures(1, &texture);
     
    112116      // build the Texture
    113117      glTexImage2D(GL_TEXTURE_2D,
    114                    0,
    115                    GL_RGBA,
    116                    w, h,
    117                    0,
    118                    GL_RGBA,
    119                    GL_UNSIGNED_BYTE,
    120                    image->pixels);
     118                   0,
     119                   GL_RGBA,
     120                   w, h,
     121                   0,
     122                   GL_RGBA,
     123                   GL_UNSIGNED_BYTE,
     124                   image->pixels);
    121125      // build the MipMaps
    122126      gluBuild2DMipmaps(GL_TEXTURE_2D,
    123                         GL_RGBA,
    124                         w,
    125                         h,
    126                         GL_RGBA,
    127                         GL_UNSIGNED_BYTE,
    128                         image->pixels);
    129      
     127                        GL_RGBA,
     128                        w,
     129                        h,
     130                        GL_RGBA,
     131                        GL_UNSIGNED_BYTE,
     132                        image->pixels);
     133
    130134      SDL_FreeSurface(image); /* No longer needed */
    131      
     135
    132136      return texture;
    133137    }
     
    143147    {
    144148      if (imageName)
    145         {
    146           SDL_Surface* tmpSurf;
    147           if (this->texture)
    148             glDeleteTextures(1, &this->texture);
    149           // load the new Image to memory
    150           tmpSurf = IMG_Load(imageName);
    151           if(!tmpSurf)
    152             {
    153               PRINTF(1)("IMG_Load: %s\n", IMG_GetError());
    154               return false;
    155             }
     149        {
     150          SDL_Surface* tmpSurf;
     151          if (this->texture)
     152            glDeleteTextures(1, &this->texture);
     153          // load the new Image to memory
     154          tmpSurf = IMG_Load(imageName);
     155          if(!tmpSurf)
     156            {
     157              PRINTF(1)("IMG_Load: %s\n", IMG_GetError());
     158              return false;
     159            }
    156160
    157           GLubyte* pixels = (GLubyte*)tmpSurf->pixels;
     161          GLubyte* pixels = (GLubyte*)tmpSurf->pixels;
    158162
    159           PRINTF(3)("loading Image %s\n", imageName);
    160           if (tmpSurf)
    161             this->texture = loadTexToGL(tmpSurf);
     163          PRINTF(3)("loading Image %s\n", imageName);
     164          if (tmpSurf)
     165            this->texture = loadTexToGL(tmpSurf);
    162166
    163          
    164           SDL_FreeSurface(tmpSurf);
    165           return true;
    166         }
     167
     168          SDL_FreeSurface(tmpSurf);
     169          return true;
     170        }
    167171      else
    168         {
    169           PRINTF(2)("Image not Found: %s\n", imageName);
    170           return false;
    171         }
     172        {
     173          PRINTF(2)("Image not Found: %s\n", imageName);
     174          return false;
     175        }
    172176    }
    173177}
Note: See TracChangeset for help on using the changeset viewer.