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
| void Terrain::loadTextures()
{
sf::Image textures[4];
std::string srcTextures[4] =
{
m_srcHeightmap,
"textures/sand.jpg",
"textures/grass.jpg",
"textures/rock.jpg"
};
glGenTextures(4, m_id_tex);
for(uint i=0; i<4; i++)
{
if( textures[i].LoadFromFile(srcTextures[i]) == false )
{
std::cout << "Terrain : Erreur lors du chargement de la texture " << srcTextures[i] << "." << std::endl;
std::exit(1);
}
glBindTexture(GL_TEXTURE_2D, m_id_tex[i]);
/* Génération de la mipmap */
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, textures[i].GetWidth(), textures[i].GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE, textures[i].GetPixelsPtr());
}
} |
Partager