Texture2D ResourceManager::loadTextureFromFile(const GLchar *file, GLboolean alpha, GLboolean repeat) { // Create Texture object Texture2D texture; if (alpha) { texture.Internal_Format = GL_RGBA; texture.Image_Format = GL_RGBA; } if (repeat) { texture.Wrap_S = GL_REPEAT; texture.Wrap_T = GL_REPEAT; } // Load image int width, height; unsigned char* image = SOIL_load_image(file, &width, &height, 0, texture.Image_Format == GL_RGBA ? SOIL_LOAD_RGBA : SOIL_LOAD_RGB); if (!image){ std::cout << "ERROR::TEXTURE: " << SOIL_last_result() << std::endl; return texture; } // Now generate texture texture.Generate(width, height, image); // And finally free image data SOIL_free_image_data(image); return texture; }
Texture2D ResourceManager::loadTextureFromFile(const GLchar * file, GLboolean alpha) { Texture2D texture; if (alpha) { texture.InternalFormat = GL_RGBA; texture.ImageFormat = GL_RGBA; } // Load image and generate texture, then clear resources int width, height; unsigned char* image = SOIL_load_image(file, &width, &height, 0, texture.ImageFormat == GL_RGBA ? SOIL_LOAD_RGBA : SOIL_LOAD_RGB); texture.Generate(width, height, image); SOIL_free_image_data(image); return texture; }
Texture2D ResourceManager::loadTextureFromFile(const GLchar *file, GLboolean alpha) { // Create Texture object Texture2D texture; if (alpha) { texture.Internal_Format = GL_RGBA; texture.Image_Format = GL_RGBA; } // Load image int width, height; unsigned char* image = SOIL_load_image(file, &width, &height, 0, texture.Image_Format == GL_RGBA ? SOIL_LOAD_RGBA : SOIL_LOAD_RGB); // Now generate texture texture.Generate(width, height, image); // And finally free image data SOIL_free_image_data(image); return texture; }