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
| #include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
int main(int argc, char *argv[])
{
SDL_Surface *ecran = NULL, *lignes[256] = {NULL};
SDL_Rect position;
int i = 0, j = 255;
SDL_Init(SDL_INIT_VIDEO);
ecran = SDL_SetVideoMode(640, 256, 32, SDL_HWSURFACE); // Hauteur de 256 pixels
for (i = 0 ; i <= 255 ; i++)
lignes[i] = SDL_CreateRGBSurface(SDL_HWSURFACE, 640, 1, 32, 0, 0, 0, 0); // Allocation des 256 surfaces
SDL_WM_SetCaption("Mon dégradé en SDL !", NULL);
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 255, 255, 255)); // je mets la surface ecran en BLANC//
for ( i = 0 ; i <= 255 ; i++)
{ position.x = 0;
position.y = i;
for ( j = 255 ; j>= 0 ; j--)
{
SDL_FillRect(lignes[i],NULL,SDL_MapRGB(ecran->format,j,j,j));
SDL_BlitSurface(lignes[i],NULL,ecran,&position);
}
}
SDL_Flip(ecran);
pause();
for( i = 255 ; i>=0; i--)
SDL_FreeSurface(lignes[i]);
SDL_Quit();
return EXIT_SUCCESS;
}
void pause()
{
int continuer = 1;
SDL_Event event;
while (continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
}
}
} |
Partager