added epic space music
This commit is contained in:
parent
f0471ffc32
commit
5ccf0ed4fd
2
Makefile
2
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)
|
||||
|
30
window.c
30
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 <GL4D/gl4duw_SDL2.h>
|
||||
#include <SDL_mixer.h>
|
||||
|
||||
/* 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);
|
||||
|
Loading…
Reference in New Issue
Block a user