diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-08-24 00:25:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-24 00:25:31 +0100 |
commit | a326354ea6fccf76665a4212bf14daeba0f52ec8 (patch) | |
tree | 18cd2deb0c30b38d8ca7c5305735d2323259e020 /src/imageloader.cpp | |
parent | 0a49874288f92c120d7e165550eb6dbbe1ef7307 (diff) | |
parent | 5403490b941f7c031bf1aafdb91b1098f69edbf2 (diff) | |
download | YAGE-0.1.0.tar.gz YAGE-0.1.0.zip |
Merge pull request #3 from ymherklotz/developv0.1.0
Merge develop to master
Diffstat (limited to 'src/imageloader.cpp')
-rw-r--r-- | src/imageloader.cpp | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/src/imageloader.cpp b/src/imageloader.cpp index 241cf588..95c73021 100644 --- a/src/imageloader.cpp +++ b/src/imageloader.cpp @@ -17,37 +17,44 @@ namespace yage Texture ImageLoader::loadPng(const std::string &file_path) { - Texture texture = {}; + Texture texture = {}; - std::vector<unsigned char> in; - std::vector<unsigned char> out; - unsigned long width, height; + std::vector<unsigned char> in; + std::vector<unsigned char> out; + unsigned long width, height; - if(!IoManager::readFileToBuffer(file_path, in)) - throw std::runtime_error("Failed to load '"+file_path+"' to buffer"); + if (!IoManager::readFileToBuffer(file_path, in)) { + throw std::runtime_error("Failed to load '" + file_path + + "' to buffer"); + } - int error_code = decodePNG(out, width, height, &in[0], in.size()); - if(error_code != 0) - throw std::runtime_error("Failed to load '"+file_path+"' to png with error code"+std::to_string(error_code)); + int error_code = decodePNG(out, width, height, &in[0], in.size()); + if (error_code != 0) { + throw std::runtime_error("Failed to load '" + file_path + + "' to png with error code" + + std::to_string(error_code)); + } - glGenTextures(1, &texture.id); - - glBindTexture(GL_TEXTURE_2D, texture.id); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, &out[0]); + glGenTextures(1, &texture.id); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glBindTexture(GL_TEXTURE_2D, texture.id); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, + GL_UNSIGNED_BYTE, &out[0]); - glGenerateMipmap(GL_TEXTURE_2D); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + GL_LINEAR_MIPMAP_LINEAR); - glBindTexture(GL_TEXTURE_2D, 0); + glGenerateMipmap(GL_TEXTURE_2D); - texture.width = (int)width; - texture.height = (int)height; + glBindTexture(GL_TEXTURE_2D, 0); - return texture; + texture.width = (int)width; + texture.height = (int)height; + + return texture; } - + } // yage |