1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
GLuint functions::Textures::LoadTexture( std::string filename)
{
SDL_Surface * tempImage = IMG_Load(filename.c_str());
SDL_Surface * image;
if(tempImage != NULL)
{
image = SDL_DisplayFormatAlpha(tempImage);
SDL_FreeSurface(tempImage);
}else{
std::cout << "Error: could not load " << filename << std::endl;
return 0;
}
GLuint TextureID(0);
glGenTextures(1,&TextureID);
glBindTexture(GL_TEXTURE_2D,TextureID);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->w, image->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
SDL_FreeSurface(image);
std::cout << "The image: \"" << filename << "\" loaded succesfully and have the ID: " << TextureID << std::endl;
return TextureID;
}
|