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
| #include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include <SDL/SDL_rotozoom.h>
#define TEMPS 30 // Le temps qu'il y a entre chaque augmentation de l'angle
int main(int argc, char *argv[])
{
SDL_Surface *ecran = NULL, *image = NULL, *rotation = NULL;
SDL_Rect rect;
SDL_Event event;
double angle = 0;
int continuer = 1;
int tempsPrecedent = 0, tempsActuel = 0;
SDL_Init(SDL_INIT_VIDEO);
ecran = SDL_SetVideoMode(500, 500, 32, SDL_HWSURFACE);
SDL_WM_SetCaption("Faire une Rotation avec SDL_gfx", NULL);
image = SDL_LoadBMP("image.bmp");
while(continuer)
{
SDL_PollEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
break;
}
tempsActuel = SDL_GetTicks();
if (tempsActuel - tempsPrecedent > TEMPS)
{
angle += 2; //On augmente l'angle pour que l'image tourne sur elle même
tempsPrecedent = tempsActuel;
}
else
{
SDL_Delay(TEMPS - (tempsActuel - tempsPrecedent));
}
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
rotation = rotozoomSurface(image, angle, 1.0, 1); //On transforme la surface image
//On positionne l'image en fonction de sa taille
rect.x = 200 - rotation->w / 2;
rect.y = 200 - rotation->h / 2;
SDL_BlitSurface(rotation , NULL, ecran, &rect); //On blit la rotation de la surface image
SDL_FreeSurface(rotation); //On efface rotation car on en a plus besoin
SDL_Flip(ecran);
}
SDL_FreeSurface(ecran);
SDL_FreeSurface(image);
SDL_Quit();
return EXIT_SUCCESS;
} |
Partager