Changeset 3660 in orxonox.OLD for orxonox/trunk/src/lib/graphics
- Timestamp:
- Mar 29, 2005, 11:50:51 AM (20 years ago)
- Location:
- orxonox/trunk/src/lib/graphics/importer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/graphics/importer/texture.cc
r3655 r3660 23 23 24 24 #include "graphics_engine.h" 25 26 // headers only for PathList27 #include <unistd.h>28 #include <sys/types.h>29 #include <sys/stat.h>30 #include <stdlib.h>31 #include <fstream>32 33 /**34 \brief creates a ned PathList.35 36 It is a good idea to use this as an initial List,37 because if you give on a name the Path will not be checked for its existence.38 */39 PathList::PathList()40 {41 this->pathName = NULL;42 this->next = NULL;43 }44 45 /**46 \brief Creates a new PathList with a Name.47 \param pName the Name of The Path.48 49 This function just adds the Path without checking if it exists.50 */51 PathList::PathList(char* pName)52 {53 this->pathName = new char [strlen(pName)+1];54 strcpy (this->pathName, pName);55 this->next = NULL;56 }57 58 /**59 \brief destroys a PathList60 61 It does this by deleting the Name and then delete its preceding PathList.62 */63 PathList::~PathList()64 {65 if (this->pathName)66 delete []this->pathName;67 if (this->next)68 delete this->next;69 }70 71 PathList* PathList::firstPath = NULL;72 73 /**74 \returns A Pointer to the first Path of the Pathlist75 */76 PathList* PathList::getInstance(void)77 {78 if (firstPath)79 return firstPath;80 firstPath = new PathList();81 }82 /**83 \brief Adds a new Pathlist Element.84 \param pName85 86 Adding a Path automatically checks if the Path exists,87 and if it does not it will not add it to the List.88 */89 void PathList::addPath (char* pName)90 {91 if (pName[0] == '\0')92 {93 PRINTF(2)("not Adding empty Path to the List.\n");94 return;95 }96 char* tmpPName = new char[strlen(pName)];97 strncpy(tmpPName, pName, strlen(pName)-1);98 tmpPName[strlen(pName)-1] = '\0';99 if (access (tmpPName, F_OK) == 0)100 {101 struct stat status;102 stat(tmpPName, &status);103 if (status.st_mode & S_IFDIR)104 {105 PRINTF(4)("Adding Path %s to the PathList.\n", pName);106 PathList* tmpPathList = this;107 while (tmpPathList->next)108 tmpPathList = tmpPathList->next;109 tmpPathList->next = new PathList(pName);110 }111 else112 PRINTF(2)("You tried to add non-folder %s to a PathList.\n", tmpPName);113 }114 else115 PRINTF(2)("You tried to add non-existing folder %s to a PathList.\n", tmpPName);116 delete []tmpPName;117 }118 119 120 25 121 26 /** … … 154 59 if (this->texture) 155 60 glDeleteTextures(1, &this->texture); 156 }157 158 /**159 \brief Searches for a Texture inside one of the defined Paths160 \param texName The name of the texture o search for.161 \returns pathName+texName if texName was found in the pathList. NULL if the Texture is not found.162 */163 char* Texture::searchTextureInPaths(const char* texName) const164 {165 char* tmpName = NULL;166 PathList* pList = PathList::getInstance();167 while (pList)168 {169 if (pList->pathName)170 {171 tmpName = new char [strlen(pList->pathName)+strlen(texName)+1];172 strcpy(tmpName, pList->pathName);173 }174 else175 {176 tmpName = new char [strlen(texName)+1];177 tmpName[0]='\0';178 }179 strcat(tmpName, texName);180 if (access (tmpName, F_OK) == 0)181 return tmpName;182 183 if (tmpName)184 delete []tmpName;185 tmpName = NULL;186 pList = pList->next;187 }188 return NULL;189 61 } 190 62 … … 231 103 if (GraphicsEngine::texturesEnabled) 232 104 { 233 char* imgNameWithPath = searchTextureInPaths(imageName); 234 if (imgNameWithPath) 235 { 236 this->map=IMG_Load(imgNameWithPath); 105 if (imageName) 106 { 107 this->map=IMG_Load(imageName); 237 108 if(!map) 238 109 { … … 249 120 pImage->format = GL_RGBA; 250 121 251 if( !IMG_isPNG(SDL_RWFromFile(im gNameWithPath, "rb")) && !IMG_isJPG(SDL_RWFromFile(imgNameWithPath, "rb")))122 if( !IMG_isPNG(SDL_RWFromFile(imageName, "rb")) && !IMG_isJPG(SDL_RWFromFile(imageName, "rb"))) 252 123 for (int i=0;i<map->h * map->w *3;i+=3) 253 124 { … … 268 139 else 269 140 { 270 PRINTF(2)("Image not Found: %s\n", im gNameWithPath);141 PRINTF(2)("Image not Found: %s\n", imageName); 271 142 return false; 272 143 } … … 285 156 if (GraphicsEngine::texturesEnabled) 286 157 { 287 char* imgNameWithPath = searchTextureInPaths(imageName); 288 if (imgNameWithPath) 289 { 290 if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".bmp", 4)) 158 if (imageName) 159 { 160 if (!strncmp(imageName+strlen(imageName)-4, ".bmp", 4)) 291 161 { 292 162 PRINTF(4)("Requested bmp-image. Trying to Import.\n"); 293 return this->loadBMP(im gNameWithPath);163 return this->loadBMP(imageName); 294 164 } 295 165 296 else if (!strncmp(im gNameWithPath+strlen(imgNameWithPath)-4, ".jpg", 4) || !strncmp(imgNameWithPath+strlen(imgNameWithPath)-5, ".jpg", 5))166 else if (!strncmp(imageName+strlen(imageName)-4, ".jpg", 4) || !strncmp(imageName+strlen(imageName)-5, ".jpg", 5)) 297 167 { 298 168 PRINTF(4)("Requested jpeg-image. Trying to Import\n"); 299 return this->loadJPG(im gNameWithPath);300 } 301 else if (!strncmp(im gNameWithPath+strlen(imgNameWithPath)-4, ".tga", 4))169 return this->loadJPG(imageName); 170 } 171 else if (!strncmp(imageName+strlen(imageName)-4, ".tga", 4)) 302 172 { 303 173 PRINTF(4)("Requested tga-image. Trying to Import\n"); 304 return this->loadTGA(im gNameWithPath);305 } 306 else if (!strncmp(im gNameWithPath+strlen(imgNameWithPath)-4, ".png", 4))174 return this->loadTGA(imageName); 175 } 176 else if (!strncmp(imageName+strlen(imageName)-4, ".png", 4)) 307 177 { 308 178 PRINTF(4)("Requested png-image. Trying to Import\n"); 309 return this->loadPNG(im gNameWithPath);179 return this->loadPNG(imageName); 310 180 } 311 181 else 312 182 { 313 PRINTF(2)("Requested Image was not recognized in its type. (Maybe a type-Cast-error.)\n FileName: %s", im gNameWithPath);183 PRINTF(2)("Requested Image was not recognized in its type. (Maybe a type-Cast-error.)\n FileName: %s", imageName); 314 184 return false; 315 185 } … … 317 187 else 318 188 { 319 PRINTF(2)("Image not Found: %s\n", im gNameWithPath);189 PRINTF(2)("Image not Found: %s\n", imageName); 320 190 return false; 321 191 } -
orxonox/trunk/src/lib/graphics/importer/texture.h
r3655 r3660 27 27 #endif /* HAVE_PNG_H */ 28 28 #endif /* HAVE_SDL_SDL_IMAGE_H */ 29 30 31 32 //! Class to handle lists of paths.33 /**34 \todo Ability to return Paths by itself.35 36 It is simple to use, and good, for all PathList you want.37 just create a new Pathlist, and add Paths.38 */39 class PathList40 {41 private:42 PathList();43 static PathList* firstPath; //!< A static Pointer to the first PathList in the List.44 public:45 PathList(char* pName);46 ~PathList();47 static PathList* getInstance(void);48 49 void addPath (char* pName);50 char* pathName; //!< The Name of the current Path.51 PathList* next; //!< Pointer to the next Pathlist.52 };53 29 54 30 //! A Class, that reads in Textures from different fileformats.
Note: See TracChangeset
for help on using the changeset viewer.