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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
class Ctexture
{
unsigned texture;
public :
void cree(char * image);
void select(void);
void Ctexture(char * image)
{
ILuint id;
GLuint g_textureID;
int format;
ilInit();
ilGenImages(1, &id);
ilBindImage(id);
ilLoadImage(image);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData());
if(ilGetInteger(IL_IMAGE_BPP) == 4)
alpha = 1;
else
alpha = 0;
ilBindImage(0);
ilDeleteImages(1, &id);
ilShutDown();
}
void Ctexture(void)
{
glEnable(GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, texture);
if(alpha == 1)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}else
{
glDisable(GL_BLEND);
}
}
};
//pour importer une image :
//Ctexture nomtexture;
//nomtexture.cree("nom_du_fichier");
//
//pour utiliser la texture :
//nomtexture.select(); |
Partager