From c7ea652cf06af91592b058656262b2ed610b361b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Sun, 26 Sep 2010 01:36:45 +0200 Subject: [PATCH] Petit refactor. --- erreurs.h | 6 ++++++ main.c | 23 ++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 erreurs.h diff --git a/erreurs.h b/erreurs.h new file mode 100644 index 0000000..cd2f08f --- /dev/null +++ b/erreurs.h @@ -0,0 +1,6 @@ +#define die(msg) {\ + fprintf(stderr, msg "\n"); \ + fprintf(stderr, " %s\n", SDL_GetError()); \ + exit(EXIT_FAILURE); \ +} + diff --git a/main.c b/main.c index c6cc573..2362d3a 100644 --- a/main.c +++ b/main.c @@ -1,14 +1,9 @@ #include #include #include +#include "erreurs.h" -#define die(msg) {\ - fprintf(stderr, msg "\n"); \ - fprintf(stderr, " %s\n", SDL_GetError()); \ - exit(EXIT_FAILURE); \ -} - -int main(int argc, char** argv) { +SDL_Surface* init() { if (SDL_Init(SDL_INIT_VIDEO) != 0) { die("Erreur lors de l'initialisation de SDL :"); } @@ -20,11 +15,21 @@ int main(int argc, char** argv) { } SDL_WM_SetCaption("Lew", "lew.png"); + return fenetre; +} + +void quit() { + SDL_Quit(); + exit(EXIT_SUCCESS); +} + +int main(int argc, char** argv) { + SDL_Surface* fenetre = init(); + SDL_FillRect(fenetre, NULL, SDL_MapRGB(fenetre->format, 255, 0, 128)); SDL_Flip(fenetre); while (1); - SDL_Quit(); - return EXIT_SUCCESS; + quit(); }