diff options
Diffstat (limited to 'src/texture.cpp')
| -rw-r--r-- | src/texture.cpp | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/src/texture.cpp b/src/texture.cpp index 6322ce7..9360369 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -10,25 +10,28 @@ // std libs #include <iostream> -Texture::Texture(const char* texture_path) +namespace Ogle { - glGenTextures(1, &id); - glBindTexture(GL_TEXTURE_2D, id); - // set the texture wrapping/filtering options (on the currently bound texture object) - 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_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - int width, height, nrChannels; - unsigned char *data = stbi_load(texture_path, &width, &height, &nrChannels, 0); - if (data) + Texture::Texture(const char* texture_path) { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); - glGenerateMipmap(GL_TEXTURE_2D); + glGenTextures(1, &id); + glBindTexture(GL_TEXTURE_2D, id); + // set the texture wrapping/filtering options (on the currently bound texture object) + 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_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + int width, height, nrChannels; + unsigned char *data = stbi_load(texture_path, &width, &height, &nrChannels, 0); + if (data) + { + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); + glGenerateMipmap(GL_TEXTURE_2D); + } + else + { + std::cout << "Failed to load texture" << std::endl; + } + stbi_image_free(data); } - else - { - std::cout << "Failed to load texture" << std::endl; - } - stbi_image_free(data); } |
