Texture loading
This function loads in a texture from a file using a 'SOIL' function. The texture paramaters are then set with a series of 'gl' functions. Next the mipmap is generated, the texture is binded and then the image data is cleared ready for the next texture to be loaded in.
void Texture::LoadFromFile(const char* path)
{
if (_texture)
{
glDeleteTextures(1, &_texture);
}
unsigned char* image = SOIL_load_image(path, &_width, &_height, NULL, SOIL_LOAD_RGBA);
glGenTextures(1, &_texture);
glBindTexture(_type, _texture);
glTexParameteri(_type, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(_type, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
if (image)
{
glTexImage2D(_type, 0, GL_RGBA, _width, _height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
glGenerateMipmap(GL_TEXTURE_2D);
}
else
{
cout << "Texture error could not load image: " << path << endl;
}
glActiveTexture(0);
glBindTexture(_type, 0);
SOIL_free_image_data(image);
}