7 #include <GLFW\glfw3.h>
9 #define STB_IMAGE_IMPLEMENTATION
10 #include "stb_image.h"
15 unsigned int texture_id;
16 Texture(std::string filepath);
25 bool USE_DEBUG2 = false;
28 Texture::Texture(std::string filepath)
30 //stbi_set_flip_vertically_on_load(true);
32 glGenTextures(1, &this->texture_id);
34 //Load texture using stb_image
35 int width, height, nrChannels;
36 unsigned char* data = stbi_load(filepath.c_str(), &width, &height, &nrChannels, 0);
42 else if (nrChannels == 3)
44 else if (nrChannels == 4)
47 glBindTexture(GL_TEXTURE_2D, this->texture_id);
48 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, format, GL_UNSIGNED_BYTE, data);
49 glGenerateMipmap(GL_TEXTURE_2D);
51 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
52 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
53 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
54 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
56 stbi_image_free(data);
60 std::cout << "Texture loaded, info:" << std::endl;
61 std::cout << filepath << std::endl;
62 std::cout << "width: " << width << std::endl;
63 std::cout << "height: " << height << std::endl;
67 std::cout << "Loading texture: " << filepath << std::endl;
72 std::cout << "ERROR::IMAGE::LOAD_FAILED" << std::endl;
82 glBindTexture(GL_TEXTURE_2D, this->texture_id);