Problème avec SDL_SetColorKey

The_Sin Messages postés 43 Date d'inscription samedi 25 septembre 2004 Statut Membre Dernière intervention 4 février 2006 - 1 août 2005 à 16:22
bathof Messages postés 28 Date d'inscription jeudi 5 mai 2005 Statut Membre Dernière intervention 31 janvier 2009 - 4 août 2005 à 02:59
Voici mon code :<sup>





#include <SDL/SDL.h>



SDL_Surface * sEcran ;

SDL_Surface * sImage ;



void init()

{

SDL_Init(SDL_INIT_VIDEO) ;

sEcran = SDL_SetVideoMode(800, 600, 32,SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN) ;

SDL_ShowCursor(0) ;



sImage=SDL_LoadBMP("img.bmp") ;

SDL_SetColorKey(sImage, SDL_SRCCOLORKEY, SDL_MapRGB(sImage->format,0,0,0)) ;



}



void Quit()

{

SDL_FreeSurface(sImage) ;

SDL_FreeSurface(sEcran) ;

SDL_ShowCursor(1) ;

SDL_Quit() ;



exit(0) ;

}



int main(int argc, char *argv[])

{



init() ;



int up 0 , down 0, right = 0 , left = 0 ;



SDL_Event event ;

SDL_Rect rect, dest ;



rect.x = 0 ;

rect.y = 0 ;

rect.w = 80 ;

rect.h = 80 ;



dest.x = 360 ;

dest.y = 260 ;

dest.w = 80 ;

dest.h = 80 ;



while(true)

{

while(SDL_PollEvent(&event))

{

if(event.type==SDL_QUIT)

{

Quit();

}

else if(event.type==SDL_KEYDOWN)

{

if(event.key.keysym.sym==SDLK_ESCAPE)

Quit() ;

}

}





SDL_FillRect(sEcran,NULL,SDL_MapRGB(sEcran->format,8,63,15)) ;

SDL_BlitSurface(sImage,&rect,sEcran,&dest) ;

SDL_FillRect(sEcran,&rect,SDL_MapRGB(sEcran->format,4,63,55)) ;



SDL_Flip(sEcran);



}



return 0 ;



}



</sup>Le code marche bien mais quand je met

SDL_SetColorKey(sImage, SDL_SRCCOLORKEY, SDL_MapRGB(sImage->format,0,0,0)) ;

le programme se lance et quitte, je comprend pas d'où vient le pbsurtout que sans cette commande le prog marche correctement...

Merci d'avance pour l'aide que vous pourrais me fournir

1 réponse

bathof Messages postés 28 Date d'inscription jeudi 5 mai 2005 Statut Membre Dernière intervention 31 janvier 2009
4 août 2005 à 02:59
Salut,

A mon avis l'image n'a pas été chargé correctement car l'emplacement n'existe pas ou le BMP est invalide.

je te conseils donc de faire plus de test, je m'explique :

Tu init' les variables comme cela :

<SUP>SDL_Surface * sEcran = NULL;
SDL_Surface * sImage = NULL;
</SUP>pour eviter les pointeurs "flottant".

ensuite test si sdl est init' correctement :

if( SDL_Init(DL_INIT_VIDEO) == -1 ) {
printf("Erreur l'hors de l'initalisation de la SDL\n");
exit(0);
}

et à chaques fois que tu charges une image test si elle a été chargée correctement comme cela :

SDL_LoadBMP("img.bmp",sImage);
if( sImage == NULL ) {
printf("Erreur l'hors du chargement de img.bmp\n");
exit(0);
}

Bonne chance et a +.
0
Rejoignez-nous