#include "OnlyOnce.hpp" /* #include */ extern "C" { #ifndef STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION #endif // !STB_IMAGE_IMPLEMENTATION #include "stb_image.h" } GLuint loadImg(const char* path) { GLuint texture; int width, height, nrChannels; GLenum format; unsigned char* data; glGenTextures(1, &texture); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture); //Gestione minification e magnification 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); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); data = stbi_load(path, &width, &height, &nrChannels, 0); if (data) { if (nrChannels == 3) format = GL_RGB; if (nrChannels == 4) format = GL_RGBA; glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data); glGenerateMipmap(GL_TEXTURE_2D); printf("Tutto OK %d %d \n", width, height); } else { printf("LoadImage Errore nel caricare la texture\n"); printf("%s\n", stbi_failure_reason()); } stbi_image_free(data); glBindTexture(GL_TEXTURE_2D, 0); return texture; }