diff --git a/Makefile b/Makefile index eefd39b..67cbc72 100644 --- a/Makefile +++ b/Makefile @@ -49,7 +49,7 @@ else LDFLAGS += -lGL endif CPPFLAGS += $(shell sdl2-config --cflags) -LDFLAGS += -lGL4Dummies $(shell sdl2-config --libs) +LDFLAGS += -lGL4Dummies $(shell sdl2-config --libs) -lSDL2_mixer all: $(PROGNAME) $(PROGNAME): $(OBJ) $(CC) $(OBJ) $(LDFLAGS) -o $(PROGNAME) diff --git a/space.wav b/space.wav new file mode 100644 index 0000000..1399e4c Binary files /dev/null and b/space.wav differ diff --git a/window.c b/window.c index 5fcc011..ea0ef3a 100644 --- a/window.c +++ b/window.c @@ -18,6 +18,7 @@ * fenêtres système ouvrant un contexte favorable à GL4dummies. Cette * partie est dépendante de la bibliothèque SDL2 */ #include +#include /* protos de fonctions locales (static) */ static void init(void); @@ -77,8 +78,14 @@ static int _p = -1; // the object (sun, planets, pluto) number to move. static float _a = 0.0f; // rotation angle. static int _overview = 0; // boolean to toggle overview (view from the top). +static Mix_Chunk * bsound = NULL; + /*!\brief paramètre l'application et lance la boucle infinie. */ int main(int argc, char ** argv) { + if (SDL_Init(SDL_INIT_AUDIO) == -1) { + fprintf(stderr, "SDL_Init: %s\n,", Mix_GetError()); + exit(3); + } /* tentative de création d'une fenêtre pour GL4Dummies */ if(!gl4duwCreateWindow(argc, argv, /* args du programme */ "Solar System", /* titre */ @@ -103,6 +110,7 @@ int main(int argc, char ** argv) { gl4duwDisplayFunc(draw); /* boucle infinie pour éviter que le programme ne s'arrête et ferme * la fenêtre immédiatement */ + gl4duwMainLoop(); return 0; } @@ -111,6 +119,22 @@ int main(int argc, char ** argv) { * utilisées dans ce code */ void init(void) { uint id[9], sun_id, i, moon_id[18]; + int flags = MIX_INIT_MP3; + int initted = Mix_Init(flags); + if ((initted & flags) != flags) { + fprintf(stderr, "Mix_Init: Failed to init required mp3 support!\n"); + fprintf(stderr, "Mix_Init: %s\n,", Mix_GetError()); + exit(2); + } + if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) == -1) { + fprintf(stderr, "Mix_OpenAudio: %s\n,", Mix_GetError()); + exit(4); + } + if (bsound == NULL) + bsound = Mix_LoadWAV("./space.wav"); + if (Mix_PlayChannel(-1, bsound, 0) < 0) + fprintf(stderr, "Mix_PlayChannel: %s\n", Mix_GetError()); + // create all spheres. _sun = mkSphere(12, 12); /*ça fait 12x12x2 triangles !*/ @@ -121,6 +145,7 @@ void init(void) { _planet[i] = mkSphere(12, 12); } + // get all textures. sun_id = getTexFromBMP("images/2k-sun.bmp"); id[0] = getTexFromBMP("images/2k-mercury.bmp"); @@ -749,6 +774,8 @@ static void mouse(int button, int state, int x, int y) { /*!\brief à appeler à la sortie du programme. */ void sortie(void) { int i; + Mix_CloseAudio(); + Mix_Quit(); if(_sun) { freeSurface(_sun); _sun = NULL; @@ -765,6 +792,9 @@ void sortie(void) { _planet[i] = NULL; } } + if (bsound) + Mix_FreeChunk(bsound); + bsound = NULL; /* libère tous les objets produits par GL4Dummies, ici * principalement les screen */ gl4duClean(GL4DU_ALL);