diff options
author | Stijn Buys <ingar@osirion.org> | 2008-08-23 12:04:21 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-08-23 12:04:21 +0000 |
commit | 02e9a70009f79064043033abc5e597930aa11079 (patch) | |
tree | 606615f7ed162f9acc1e91f03b9745a12637d41a /src/render/textures.cc | |
parent | 375b7d96a3974a03416c600b579048e48f1580a2 (diff) |
PNG support
Diffstat (limited to 'src/render/textures.cc')
-rw-r--r-- | src/render/textures.cc | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/src/render/textures.cc b/src/render/textures.cc index 2bc6c05..6ceb7cd 100644 --- a/src/render/textures.cc +++ b/src/render/textures.cc @@ -9,6 +9,7 @@ #include "render/gl.h" #include "render/textures.h" #include "render/tga.h" +#include "render/pngfile.h" #include "sys/sys.h" #include "core/application.h" @@ -66,23 +67,34 @@ size_t Textures::load(std::string name, bool filter) if (it != registry.end()) return (*it).second; - // try the tga version - std::string filename(name); - filename.append(".tga"); - Image *image = TGA::load(filename.c_str()); - if (!image) { - // add to the registry with id 0 (texture not found) - registry[name] = 0; - return 0; - } - if (index == MAXTEXTURES) { con_error << "Texture limit " << MAXTEXTURES << " exceeded!" << std::endl; - delete image; registry[name] = 0; return 0; } + std::string filename; + Image *image = 0; + + // try the png version + filename.assign(name); + filename.append(".png"); + image = PNG::load(filename.c_str()); + + if (!image) { + // try the tga version + filename.assign(name); + filename.append(".tga"); + image = TGA::load(filename.c_str()); + + if (!image) { + // add to the registry with id 0 (texture not found) + con_warn << "Could not open " << filename << std::endl; + registry[name] = 0; + return 0; + } + } + size_t id = index; glGenTextures(1, &textures[id]); |