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
|
#include <stdlib.h>
#include <stdio.h>
#include <SDL.h>
#define BIT_COULEURS 32
#define TAILLE 1024
#define NOIR (0), (0), (0)
#define CLAIR (255), (255), (255)
#define GRIS_CLAIR (200), (200), (200)
#define GRIS_FONCE (100), (100), (100)
#define LARGEUR 10
#define HAUTEUR 500
SDL_Surface *ecran;
int main (int argc, char** argv)
{
int tempsPrecedent = 0, tempsActuel = 0;
SDL_Surface *barre;
int attente =25;
SDL_Rect dest = {32, 32, LARGEUR, HAUTEUR};
SDL_Init(SDL_INIT_VIDEO);
ecran = SDL_SetVideoMode(TAILLE, TAILLE, BIT_COULEURS, SDL_HWSURFACE | SDL_DOUBLEBUF);
barre =
SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_DOUBLEBUF, LARGEUR, HAUTEUR, 32, 0, 0, 0, 0);
SDL_FillRect(barre, NULL, SDL_MapRGB(ecran->format, GRIS_FONCE));
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, CLAIR));
SDL_BlitSurface(barre, NULL, ecran, &dest);
SDL_UpdateRect(ecran, 0, 0, TAILLE, TAILLE);
while (1)
{
tempsActuel = SDL_GetTicks();
if (tempsActuel - tempsPrecedent > attente)
{
dest.x += 5;
tempsPrecedent = tempsActuel;
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, CLAIR));
SDL_BlitSurface(barre, NULL, ecran, &dest);
SDL_Flip(ecran);
}
else
{
SDL_Delay(attente - (tempsActuel - tempsPrecedent));
}
}
SDL_Delay(100000);
SDL_FreeSurface(barre);
return EXIT_SUCCESS;
} |
Partager