
Le code erroné :
#include <stdlib.h>
#include <SDL/SDL.h>
int main ( int argc, char** argv )
{
SDL_Event event; SDL_Surface *ecran = NULL;
int continuer = 1; int clic = 0;
if (SDL_Init(SDL_INIT_VIDEO) < 0) exit(EXIT_FAILURE);
ecran = SDL_SetVideoMode(400, 400, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
while(continuer)
{
SDL_PollEvent(&event); // on passe cette ligne même sans évènement !
switch(event.type) // en fonction du dernier event !!!!!!!
{
case SDL_QUIT: continuer = 0; break;
case SDL_MOUSEBUTTONDOWN: clic++; break;
//on incrémente suivant l'état de event.type
} // fin switch(event.type)
//--------- Blits et Affichage
} // fin while(continuer)
printf("Tiens, je ne pensais pas avoir fait %i clic(s) ! \n",clic);
SDL_Quit();
return EXIT_SUCCESS;
}

Le bon code :
#include <stdlib.h>
#include <SDL/SDL.h>
int main ( int argc, char** argv )
{
SDL_Event event; SDL_Surface *ecran = NULL;
int continuer = 1; int clic = 0;
if (SDL_Init(SDL_INIT_VIDEO) < 0) exit(EXIT_FAILURE);
ecran = SDL_SetVideoMode(400, 400, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
while(continuer)
{
while (SDL_PollEvent(&event)) // correct
{
switch(event.type) // en fonction de chaque évènement du Poll
{
case SDL_QUIT: continuer = 0; break;
case SDL_MOUSEBUTTONDOWN: clic++; break;
// on compte le nombre de clic(s)
} // fin switch(event.type)
} // fin SDL_PollEvent(&event)
// --------- Blits et Affichage
} // fin while(continuer)
printf("J'ai fait %i clic(s). \n",clic);
SDL_Quit();
return EXIT_SUCCESS;
}

--> RETOUR