Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/render/textures.cc')
-rw-r--r--src/render/textures.cc25
1 files changed, 24 insertions, 1 deletions
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<std::string, size_t> 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]);
+ }
+}
+
}