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 58 59 60 61 62 63
|
/** @: permet de charger la texture (ne pas l'appeler, utilisé par YCI_CHARGEABLE, appeler plutôt charger() )
@retour: vrai si le chargement s'est bien déroulé */
bool YC_M2D_Texture::chargerProcedure()
{
YC_LeverException_F((YCP_M2D_Moteur2D::accMoteurActuel()==NULL),YC_ERR_OBJET_NON_INITIALISE,"Erreur : tentative de chargement sans YC_M2D_Moteur défini comme le moteur actuel");
char* chaine = sChemin.copieChaine();
//si un format est spécifié, on crée la texture avec ce format
if (fFormat != D3DFMT_UNKNOWN)
{
D3DXCreateTextureFromFileEx( YCP_M2D_Moteur2D::accMoteurActuel()->accDevice(), sChemin.accChaine(),
(uint)fLargeur, (uint)fHauteur, 1, D3DUSAGE_RENDERTARGET,
fFormat, D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_DEFAULT,
0xFF000000, NULL, NULL, &dxTexture);
}
//si la texture est un fichier TGA, on la charge en 32 bits
else if (strcmp(strlwr(chaine+strlen(chaine)-3),"tga")==0)
{
//essai de chargement en 32 bits A8R8G8B8
D3DXCreateTextureFromFileEx( YCP_M2D_Moteur2D::accMoteurActuel()->accDevice(), sChemin.accChaine(),
(uint)fLargeur, (uint)fHauteur, 1, D3DUSAGE_RENDERTARGET,
D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_DEFAULT,
0xFF000000, NULL, NULL, &dxTexture);
fFormat = D3DFMT_A8R8G8B8;
}
//essai de chargement en 32 bits A8R8G8B8
else if (SUCCEEDED(D3DXCreateTextureFromFileEx( YCP_M2D_Moteur2D::accMoteurActuel()->accDevice(), sChemin.accChaine(),
(uint)fLargeur, (uint)fHauteur, 1, D3DUSAGE_RENDERTARGET,
D3DFMT_A1R5G5B5, D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_DEFAULT,
0xFF000000, NULL, NULL, &dxTexture)))
{ fFormat = D3DFMT_A1R5G5B5; }
//essai de chargement en 16 bits A1R5G5B5
else if (SUCCEEDED(D3DXCreateTextureFromFileEx( YCP_M2D_Moteur2D::accMoteurActuel()->accDevice(), sChemin.accChaine(),
(uint)fLargeur, (uint)fHauteur, 1, D3DUSAGE_RENDERTARGET,
D3DFMT_A4R4G4B4, D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_DEFAULT,
0xFF000000, NULL, NULL, &dxTexture)))
{ fFormat = D3DFMT_A4R4G4B4; }
//essai de chargement en 16 bits A4R4G4B4
else if (SUCCEEDED(D3DXCreateTextureFromFileEx( YCP_M2D_Moteur2D::accMoteurActuel()->accDevice(), sChemin.accChaine(),
(uint)fLargeur, (uint)fHauteur, 1, D3DUSAGE_RENDERTARGET,
D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_DEFAULT,
0xFF000000, NULL, NULL, &dxTexture)))
{ fFormat = D3DFMT_A8R8G8B8; }
else
{ delete[] chaine;
YC_LeverException_F(true,YC_ERR_FORMAT_NON_GERE,"Erreur : impossible de charger la texture, chemin introuvable ou format de fichier non géré."); }
//infos sur la texture
D3DSURFACE_DESC Infos;
dxTexture->GetLevelDesc(0,&Infos);
//obtention de la surface associée à la texture (afin de pouvoir rendre plus tard sur la texture)
dxTexture->GetSurfaceLevel(0, &dxSurface);
//on a accès ainsi à Infos.Size, Infos.Width, Infos.Height
fTaille=(float)Infos.Size;
fLargeur=(float)Infos.Width;
fHauteur=(float)Infos.Height;
delete[] chaine;
return true;
} |
Partager