Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

imeshloader.cpp

Go to the documentation of this file.
00001 /*
00002     Sheep - A Rigid Body Dynamics Engine
00003     Copyright (C) 2001-2004 Francois Beaune
00004     Contact: http://toxicengine.sourceforge.net/
00005 
00006     This file is part of Sheep.
00007 
00008     Sheep is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     Sheep is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with Sheep; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00023 #include "imeshloader.h"    // include first
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     // Some images start with the origin in the lower left,
00034     // while others start with the origin in the upper left.
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     // Discard loading errors.
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 }

Generated on Tue May 11 01:31:50 2004 for toxic by doxygen 1.3.6