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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
SDL_Rect rect;
SDL_Surface *Screen, *rectangle;
FILE *file;
SDL_Surface* image;
int init_image = 0;
int i = 0;
// Fonction d'affichage
void affichage2()
{
SDL_FillRect(Screen, NULL, SDL_MapRGB(Screen->format, 12, 105, 85));
// zone
rect.x = (Screen->w / 2) - (rect.w / 2);
rect.y = (Screen->h / 2) - (rect.h / 2);
rect.w = Screen->w / 2;
rect.h = Screen->h / 2;
// Blit de la surface à l'écran et affichage
SDL_BlitSurface(rectangle,NULL,Screen,&rect);
SDL_Flip(Screen);
}
int main (int argc, char **argv)
{
// Initialisation SDL
if (SDL_Init (SDL_INIT_VIDEO) < 0) {
fprintf (stderr, "Erreur d'initialisation de SDL: %s\n",
SDL_GetError ());
return 1;
}
atexit (SDL_Quit);
// Initialisation SDL_Video
Screen = SDL_SetVideoMode (640, 480, 32, SDL_SWSURFACE| SDL_RESIZABLE |
SDL_DOUBLEBUF );
if (Screen == NULL) {
fprintf (stderr, "Erreur d'initialisation: %s\n",
SDL_GetError ());
return 2;
}
// Allocation surface
rectangle = SDL_CreateRGBSurface(SDL_SWSURFACE,
320, 240 , 32,
0, 0, 0, 0);
// Titre
SDL_WM_SetCaption ("SDL Test", NULL);
affichage2();
int continuer = 1;
SDL_Event event;
int new_largeur, new_hauteur;
while (continuer) // boucle évenementielle
{
SDL_WaitEvent(&event); // Attendre un évènement
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
break;
case SDL_VIDEORESIZE:
new_largeur = event.resize.w; // <- largeur
new_hauteur = event.resize.h; // <- hauteur
Screen=SDL_SetVideoMode(new_largeur,new_hauteur,32,SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_RESIZABLE);
rect.w = new_largeur / 2; // on spécifie la nouvelle taille du rectangle
rect.h = new_hauteur / 2;
SDL_FillRect(rectangle, NULL,SDL_MapRGB(Screen->format, 255, 0, 0));
SDL_FillRect(Screen, NULL, 0);
rectangle = SDL_CreateRGBSurface(SDL_HWSURFACE, rect.w, rect.h, 32, 0, 0, 0, 0);
SDL_BlitSurface(rectangle,NULL,Screen,&rect);
return 0;
}
}
} |
Partager