From 02e9a70009f79064043033abc5e597930aa11079 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 23 Aug 2008 12:04:21 +0000 Subject: PNG support --- src/render/textures.cc | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'src/render/textures.cc') 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]); -- cgit v1.2.3