00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "imeshloader.h"
00024 #include "common/misc/stringutils.h"
00025
00026 #include <cassert>
00027 #include <IL/il.h>
00028
00029 using namespace sheep;
00030 using namespace std;
00031
00032 bool sheep::LoadImage(const string &filename) {
00033
00034
00035 ilEnable(IL_ORIGIN_SET);
00036 ilOriginFunc(IL_ORIGIN_UPPER_LEFT);
00037
00038 assert(ilGetError() == IL_NO_ERROR);
00039 assert(ilGetInteger(IL_ORIGIN_MODE) == IL_ORIGIN_UPPER_LEFT);
00040
00041 const bool successful =
00042 ilLoadImage(const_cast<ILstring>(filename.c_str())) == IL_TRUE ? true : false;
00043
00044
00045 while(ilGetError() != IL_NO_ERROR);
00046
00047 return successful;
00048 }
00049
00050 bool sheep::TryLoadingImage(const string &path, const string &filename) {
00051 if(LoadImage(path + filename))
00052 return true;
00053
00054 if(LoadImage(filename))
00055 return true;
00056
00057 if(LoadImage(path + StringUtils::GetFilename(filename)))
00058 return true;
00059
00060 return false;
00061 }
00062
00063 FILE *sheep::TryOpeningFile(const string &path,
00064 const string &filename,
00065 const char *mode)
00066 {
00067 FILE *file;
00068
00069 if((file = fopen((path + filename).c_str(), mode)))
00070 return file;
00071
00072 if((file = fopen(filename.c_str(), mode)))
00073 return file;
00074
00075 if((file = fopen((path + StringUtils::GetFilename(filename)).c_str(), mode)))
00076 return file;
00077
00078 return 0;
00079 }