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
| #include <stdio.h>
#include <stdlib.h>
#include "SDL/SDL.h"
#define WIDTH_WINDOW 640
#define HEIGHT_WINDOW 256
#define NAME_WINDOW "TEST SDL : Degrader inverser"
void pause() ;
void startSDL() ;
int main(int argc, char *argv[])
{
//Initialisation
int a, b, c ;
a = 0 ;
b = 255 ;
c = 0 ;
SDL_Surface *screen = NULL ;
SDL_Surface *degrade[HEIGHT_WINDOW] = {NULL} ;
SDL_Rect position ;
//Start SDL, name of windows
startSDL() ;
SDL_WM_SetCaption(NAME_WINDOW, NULL);
screen = SDL_SetVideoMode(WIDTH_WINDOW, HEIGHT_WINDOW, 32, SDL_HWSURFACE) ;
//Color of screen
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)) ;
while(a <= (HEIGHT_WINDOW - 1))
{
degrade[a] = SDL_CreateRGBSurface(SDL_HWSURFACE, WIDTH_WINDOW, 1, 32, 0, 0, 0, 0) ;
a++ ;
}
//Color of degradé, blitter degradé
while(b >= 0)
{
position.x = 0 ;
position.y = b ;
SDL_FillRect(degrade[b], NULL, SDL_MapRGB(screen->format, b, b, b)) ;
SDL_BlitSurface(degrade[b], NULL, screen, &position) ;
b-- ;
}
//Update
SDL_Flip(screen) ;
pause() ;
//Free
while (c <= 255)
{
SDL_FreeSurface(degrade[c]) ;
c++ ;
}
pause() ;
SDL_Quit() ;
return EXIT_SUCCESS ;
}
void pause()
{
int i = 1;
SDL_Event event;
while (i)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
i = 0;
}
}
}
void startSDL()
{
//Start SDL, if no start display error
if(SDL_Init(SDL_INIT_VIDEO))
{
fprintf(stderr, "Error SDL : %s\n", SDL_GetError()) ;
exit(EXIT_FAILURE) ;
}
} |
Partager