diff options
-rw-r--r-- | src/render/state.cc | 3 | ||||
-rw-r--r-- | src/render/textures.cc | 33 | ||||
-rw-r--r-- | src/render/textures.h | 16 |
3 files changed, 37 insertions, 15 deletions
diff --git a/src/render/state.cc b/src/render/state.cc index 996b94c..649493e 100644 --- a/src/render/state.cc +++ b/src/render/state.cc @@ -6,6 +6,7 @@ #include "render/state.h" #include "render/gl.h" +#include "render/render.h" namespace render { @@ -41,7 +42,7 @@ void State::clear() gl::clearcolor(0.0f, 0.0f, 0.0f, 1.0f); // load identity matrices - gl::matrixmode(GL_MODELVIEW); + gl::matrixmode(GL_PROJECTION); gl::loadidentity(); gl::matrixmode(GL_MODELVIEW); diff --git a/src/render/textures.cc b/src/render/textures.cc index 60c82c2..a340814 100644 --- a/src/render/textures.cc +++ b/src/render/textures.cc @@ -74,7 +74,7 @@ void Textures::clear() memset(textures,0, sizeof(textures)); } -void Textures::unload(std::string name) +void Textures::unload(const std::string &name) { iterator it = registry.find(name); if (it != registry.end()) { @@ -82,13 +82,13 @@ void Textures::unload(std::string name) size_t id = (*it).second; if (textures[id]) { glDeleteTextures(1, &textures[id]); + textures[id] = 0; } registry.erase(it); - } } -void Textures::unload(size_t id) +void Textures::unload(const size_t id) { // find in map for (iterator it = registry.begin(); it != registry.end(); it++) { @@ -97,6 +97,7 @@ void Textures::unload(size_t id) size_t id = (*it).second; if (textures[id]) { glDeleteTextures(1, &textures[id]); + textures[id] = 0; } registry.erase(it); break; @@ -104,7 +105,15 @@ void Textures::unload(size_t id) } } -size_t Textures::load(std::string name, bool filter) +size_t Textures::load(const char *name, const bool filter) +{ + if (name) + return load(std::string(name), filter); + else + return 0; +} + +size_t Textures::load(const std::string &name, const bool filter) { // check if it is already loaded iterator it = registry.find(name); @@ -176,7 +185,7 @@ size_t Textures::load(std::string name, bool filter) return id; } -size_t Textures::find(std::string name) +size_t Textures::find(const std::string &name) { size_t id = 0; iterator it = registry.find(name); @@ -185,7 +194,15 @@ size_t Textures::find(std::string name) return id; } -size_t Textures::bind(std::string name, bool filter) +size_t Textures::bind(const char *name, const bool filter) +{ + if (name) + return bind(std::string(name), filter); + else + return 0; +} + +size_t Textures::bind(const std::string &name, const bool filter) { size_t id = 0; iterator it = registry.find(name); @@ -199,7 +216,7 @@ size_t Textures::bind(std::string name, bool filter) return id; } -size_t Textures::bind(size_t texture, bool filter) +size_t Textures::bind(const size_t texture, const bool filter) { size_t id = texture; if (!textures[id]) @@ -210,7 +227,7 @@ size_t Textures::bind(size_t texture, bool filter) return id; } -void Textures::set_filter(bool filter) +void Textures::set_filter(const bool filter) { if (filter) { glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); diff --git a/src/render/textures.h b/src/render/textures.h index aa47bfa..5a20641 100644 --- a/src/render/textures.h +++ b/src/render/textures.h @@ -30,24 +30,28 @@ public: /// Load a texture /** Returns 0 on failure, and the texture index on success */ - static size_t load(std::string name, bool filter = true); + static size_t load(const std::string & name, const bool filter = true); + + static size_t load(const char *name, const bool filter = true); /// bind a texture for OpenGL usage /** Returns 0 on failure, and the texture index on success */ - static size_t bind(std::string name, bool filter = true); + static size_t bind(const std::string &name, const bool filter = true); + + static size_t bind(const char *name, const bool filter = true); /// bind a texture for OpenGL usage - static size_t bind(size_t texture, bool filter = true); + static size_t bind(const size_t texture, const bool filter = true); /// find the texture index for a given name - static size_t find(std::string name); + static size_t find(const std::string &name); /// unload a texture - static void unload(size_t id); + static void unload(const size_t id); /// unload a texture - static void unload(std::string name); + static void unload(const std::string &name); /// list loaded textures static void list(); |