Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3622 in orxonox.OLD for orxonox/trunk/src/lib/graphics


Ignore:
Timestamp:
Mar 21, 2005, 6:28:31 PM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: small patch to enable/disable textures with one single switch: GraphicsEngine::textureEnabled

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

Legend:

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

    r3621 r3622  
    160160}
    161161
     162/**
     163   \brief if Textures should be enabled
     164*/
     165bool GraphicsEngine::texturesEnabled = true;
     166
     167
    162168
    163169
  • orxonox/trunk/src/lib/graphics/importer/texture.cc

    r3590 r3622  
    2121
    2222#include "texture.h"
     23
     24#include "graphics_engine.h"
    2325
    2426// headers only for PathList
     
    195197bool Texture::loadTexToGL (Image* pImage)
    196198{
    197   PRINTF(4)("Loading texture to OpenGL-Environment.\n");
    198   glGenTextures(1, &this->texture);
    199   glBindTexture(GL_TEXTURE_2D, this->texture);
    200   /* not Working, and not needed.
    201   glTexImage2D( GL_TEXTURE_2D, 0, 3, width,
    202                 height, 0, GL_BGR,
    203                 GL_UNSIGNED_BYTE, map->pixels );
    204   */
    205   gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pImage->width, pImage->height, pImage->format, GL_UNSIGNED_BYTE, pImage->data);
    206  
    207   glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
    208   glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
    209 }
    210 
     199  if (GraphicsEngine::texturesEnabled)
     200    {
     201      PRINTF(4)("Loading texture to OpenGL-Environment.\n");
     202      glGenTextures(1, &this->texture);
     203      glBindTexture(GL_TEXTURE_2D, this->texture);
     204      /* not Working, and not needed.
     205         glTexImage2D( GL_TEXTURE_2D, 0, 3, width,
     206         height, 0, GL_BGR,
     207         GL_UNSIGNED_BYTE, map->pixels );
     208      */
     209      gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pImage->width, pImage->height, pImage->format, GL_UNSIGNED_BYTE, pImage->data);
     210     
     211      glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
     212      glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);     
     213    }
     214}
    211215
    212216#ifdef HAVE_SDL_SDL_IMAGE_H
    213217bool Texture::loadImage(char* imageName)
    214218{
    215   char* imgNameWithPath = searchTextureInPaths(imageName);
    216   if (imgNameWithPath)
    217     {
    218       this->map=IMG_Load(imgNameWithPath);
    219       if(!map)
    220         {
    221           PRINTF(1)("IMG_Load: %s\n", IMG_GetError());
     219  if (GraphicsEngine::texturesEnabled)
     220    {
     221      char* imgNameWithPath = searchTextureInPaths(imageName);
     222      if (imgNameWithPath)
     223        {
     224          this->map=IMG_Load(imgNameWithPath);
     225          if(!map)
     226            {
     227              PRINTF(1)("IMG_Load: %s\n", IMG_GetError());
     228              return false;
     229            }
     230          pImage->height = map->h;
     231          pImage->width  = map->w;
     232          pImage->data   = (GLubyte*)map->pixels;
     233          pImage->bpp    = map->format->BytesPerPixel;
     234          if (pImage->bpp == 3)
     235            pImage->format = GL_RGB;
     236          else if (pImage->bpp == 4)
     237            pImage->format = GL_RGBA;
     238         
     239          if( !IMG_isPNG(SDL_RWFromFile(imgNameWithPath, "rb")) && !IMG_isJPG(SDL_RWFromFile(imgNameWithPath, "rb")))
     240            for (int i=0;i<map->h * map->w *3;i+=3)
     241              {
     242                GLuint temp = pImage->data[i];
     243                pImage->data[i] = pImage->data[i+2];
     244                pImage->data[i+2] = temp;
     245              }
     246          /* this is the real swapping algorithm */
     247          for( int i = 0 ; i < (pImage->height / 2) ; ++i )
     248            for( int j = 0 ; j < pImage->width * pImage->bpp; j += pImage->bpp )
     249              for(int k = 0; k < pImage->bpp; ++k)
     250                swap( pImage->data[ (i * pImage->width * pImage->bpp) + j + k], pImage->data[ ( (pImage->height - i - 1) * pImage->width * pImage->bpp ) + j + k]);
     251         
     252          this->loadTexToGL (this->pImage);
     253          SDL_FreeSurface(map);
     254          this->pImage->data = NULL;
     255        }
     256      else
     257        {
     258          PRINTF(2)("Image not Found: %s\n", imgNameWithPath);
    222259          return false;
    223260        }
    224       pImage->height = map->h;
    225       pImage->width  = map->w;
    226       pImage->data   = (GLubyte*)map->pixels;
    227       pImage->bpp    = map->format->BytesPerPixel;
    228       if (pImage->bpp == 3)
    229         pImage->format = GL_RGB;
    230       else if (pImage->bpp == 4)
    231         pImage->format = GL_RGBA;
    232          
    233       if( !IMG_isPNG(SDL_RWFromFile(imgNameWithPath, "rb")) && !IMG_isJPG(SDL_RWFromFile(imgNameWithPath, "rb")))
    234         for (int i=0;i<map->h * map->w *3;i+=3)
    235           {
    236             GLuint temp = pImage->data[i];
    237             pImage->data[i] = pImage->data[i+2];
    238             pImage->data[i+2] = temp;
    239           }
    240       /* this is the real swapping algorithm */
    241       for( int i = 0 ; i < (pImage->height / 2) ; ++i )
    242         for( int j = 0 ; j < pImage->width * pImage->bpp; j += pImage->bpp )
    243           for(int k = 0; k < pImage->bpp; ++k)
    244             swap( pImage->data[ (i * pImage->width * pImage->bpp) + j + k], pImage->data[ ( (pImage->height - i - 1) * pImage->width * pImage->bpp ) + j + k]);
    245  
    246       this->loadTexToGL (this->pImage);
    247       SDL_FreeSurface(map);
    248       this->pImage->data = NULL;
    249     }
    250   else
    251     {
    252       PRINTF(2)("Image not Found: %s\n", imgNameWithPath);
    253       return false;
    254261    }
    255262}
     
    264271bool Texture::loadImage(char* imageName)
    265272{
    266   char* imgNameWithPath = searchTextureInPaths(imageName);
    267   if (imgNameWithPath)
    268     {
    269       if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".bmp", 4))
    270         {
    271           PRINTF(4)("Requested bmp-image. Trying to Import.\n");
    272           return this->loadBMP(imgNameWithPath);
    273         }
    274      
    275       else if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".jpg", 4) || !strncmp(imgNameWithPath+strlen(imgNameWithPath)-5, ".jpg", 5))
    276         {
    277           PRINTF(4)("Requested jpeg-image. Trying to Import\n");
    278           return this->loadJPG(imgNameWithPath);
    279         }
    280       else if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".tga", 4))
    281         {
    282           PRINTF(4)("Requested tga-image. Trying to Import\n");
    283           return this->loadTGA(imgNameWithPath);
    284         }
    285       else if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".png", 4))
    286         {
    287           PRINTF(4)("Requested png-image. Trying to Import\n");
    288           return this->loadPNG(imgNameWithPath);
     273  if (GraphicsEngine::texturesEnabled)
     274    {
     275      char* imgNameWithPath = searchTextureInPaths(imageName);
     276      if (imgNameWithPath)
     277        {
     278          if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".bmp", 4))
     279            {
     280              PRINTF(4)("Requested bmp-image. Trying to Import.\n");
     281              return this->loadBMP(imgNameWithPath);
     282            }
     283         
     284          else if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".jpg", 4) || !strncmp(imgNameWithPath+strlen(imgNameWithPath)-5, ".jpg", 5))
     285            {
     286              PRINTF(4)("Requested jpeg-image. Trying to Import\n");
     287              return this->loadJPG(imgNameWithPath);
     288            }
     289          else if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".tga", 4))
     290            {
     291              PRINTF(4)("Requested tga-image. Trying to Import\n");
     292              return this->loadTGA(imgNameWithPath);
     293            }
     294          else if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".png", 4))
     295            {
     296              PRINTF(4)("Requested png-image. Trying to Import\n");
     297              return this->loadPNG(imgNameWithPath);
     298            }
     299          else
     300            {
     301              PRINTF(2)("Requested Image was not recognized in its type. (Maybe a type-Cast-error.)\n FileName: %s", imgNameWithPath);
     302              return false;
     303            }
    289304        }
    290305      else
    291306        {
    292           PRINTF(2)("Requested Image was not recognized in its type. (Maybe a type-Cast-error.)\n FileName: %s", imgNameWithPath);
     307          PRINTF(2)("Image not Found: %s\n", imgNameWithPath);
    293308          return false;
    294309        }
    295310    }
    296   else
    297     {
    298       PRINTF(2)("Image not Found: %s\n", imgNameWithPath);
    299       return false;
    300     }
    301 }
    302 
     311}
    303312/**
    304313   \brief reads in a Windows BMP-file, and imports it to openGL.
Note: See TracChangeset for help on using the changeset viewer.