From 183f0f0b905715f0d89b38174fdfd44641c1a79c Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 12 Aug 2009 12:03:18 +0000 Subject: src/model filenames cleanup, parse .map texture coordinates, early loading of material textures --- src/render/textures.cc | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/render/textures.cc') diff --git a/src/render/textures.cc b/src/render/textures.cc index 5845bb6..fe85c8d 100644 --- a/src/render/textures.cc +++ b/src/render/textures.cc @@ -23,6 +23,12 @@ namespace render std::map Textures::registry; GLuint Textures::textures[MAXTEXTURES]; +math::Vector2f Textures::texture_size[MAXTEXTURES]; + +void material_loader_func(model::Material *material) +{ + Textures::material_loader(material); +} void Textures::init() { @@ -49,10 +55,13 @@ void Textures::init() load("bitmaps/pointers/center"); load("bitmaps/pointers/control"); load("bitmaps/pointers/target"); + + model::Material::set_loader_func(Textures::material_loader); } void Textures::shutdown() { + model::Material::set_loader_func(0); clear(); } @@ -159,7 +168,7 @@ size_t Textures::load(const std::string &name, const bool filter) if (!image) { // add to the registry with id 0 (texture not found) - con_warn << "Could not open " << filename << std::endl; + con_warn << "Could not open texture " << name << std::endl; registry[name] = 0; return 0; } @@ -181,6 +190,10 @@ size_t Textures::load(const std::string &name, const bool filter) // hardware generated mipmaps (requires OpenGL 1.4) glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); } + + // enable texture wrapping + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); } else { // scaling functions glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); @@ -210,6 +223,7 @@ size_t Textures::load(const std::string &name, const bool filter) // add to the registry registry[name] = id; + texture_size[id].assign((float) image->width(), (float) image->height()); // delete image data delete image; @@ -258,4 +272,13 @@ size_t Textures::bind(const size_t texture, const bool filter) return id; } +void Textures::material_loader(model::Material *material) +{ + if ((material->flags() & model::Material::Texture) & (material->texture().size())) { + size_t id = load(material->texture()); + material->set_texture_id(id); + material->set_size(texture_size[id]); + } +} + } -- cgit v1.2.3