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 64 65 66 67 68 69 70 71 72 73 74
| int main(int argc, char *argv[])
{
int i1,j1,degrade;
SDL_Rect position,positionFond;
position.x = 0;
position.y = 0;
SDL_Surface *ecran , *imageFond; // Le pointeur qui va stocker la surface de l'écran
SDL_Surface *pixel = NULL;
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER); // Chargement de la vidéo, de l'audio et du timer
ecran = SDL_SetVideoMode(700, 550, 32, SDL_HWSURFACE | SDL_DOUBLEBUF); // On tente d'ouvrir une fenêtre
if (ecran == NULL) // Si l'ouverture a échoué, on écrit l'erreur et on arrête
{
fprintf(stderr, "Impossible de charger le mode vidéo : %s\n", SDL_GetError());
exit(EXIT_FAILURE);
}
SDL_WM_SetCaption("Jeu !!", "Jeu");
// Coloration de la surface ecran
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
pixel =SDL_CreateRGBSurface(SDL_HWSURFACE,1,1,32,0,0,0,0);
for(i1=0 ; i1 <= ecran->w ; i1++)
{
position.x = i1 ;
for(j1=0 ; j1 <= ecran->h ; j1++)
{
degrade=(i1+j1)*255/(ecran->h+ecran->w-2); // ici on calcule la couleur pour chaque pixel ;)
SDL_FillRect(pixel,0,SDL_MapRGB(ecran->format,degrade,0,0));
position.y = j1 ;
SDL_BlitSurface(pixel,NULL,ecran,&position);
}
}
SDL_FreeSurface(pixel);
SDL_Flip(ecran); // Mise à jour de l'écran avec sa nouvelle couleur
pause();
SDL_Quit();
} |
Partager