-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
faits en cours le lundi 18/03/2024
Farès Belhadj
committed
Mar 21, 2024
1 parent
878b5a5
commit 2426667
Showing
36 changed files
with
5,788 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Makefile | ||
# Auteur : Farès BELHADJ | ||
# Email : [email protected] | ||
# Date : 28/04/2020 | ||
# définition des commandes utilisées | ||
CC = gcc | ||
ECHO = echo | ||
RM = rm -f | ||
TAR = tar | ||
ZIP = zip | ||
MKDIR = mkdir | ||
CHMOD = chmod | ||
CP = rsync -R | ||
# déclaration des options du compilateur | ||
CFLAGS = -Wall -O3 | ||
CPPFLAGS = -I. | ||
LDFLAGS = -lm | ||
# définition des fichiers et dossiers | ||
PACKNAME = demo | ||
PROGNAME = rgb | ||
VERSION = 1.3 | ||
distdir = $(PACKNAME)_$(PROGNAME)-$(VERSION) | ||
HEADERS = animations.h audioHelper.h mobile.h | ||
SOURCES = animations.c audioHelper.c window.c dancing_cubes.c phy.c mobile.c | ||
MSVCSRC = $(patsubst %,<ClCompile Include=\"%\\\" \\/>,$(SOURCES)) | ||
OBJ = $(SOURCES:.c=.o) | ||
DOXYFILE = documentation/Doxyfile | ||
VSCFILES = $(PROGNAME).vcxproj $(PROGNAME).sln | ||
EXTRAFILES = COPYING $(wildcard shaders/*.?s images/*) $(VSCFILES) takeonme.mod | ||
DISTFILES = $(SOURCES) Makefile $(HEADERS) $(DOXYFILE) $(EXTRAFILES) | ||
# Traitements automatiques pour ajout de chemins et options (ne pas modifier) | ||
ifneq (,$(shell ls -d /usr/local/include 2>/dev/null | tail -n 1)) | ||
CPPFLAGS += -I/usr/local/include | ||
endif | ||
ifneq (,$(shell ls -d $(HOME)/local/include 2>/dev/null | tail -n 1)) | ||
CPPFLAGS += -I$(HOME)/local/include | ||
endif | ||
ifneq (,$(shell ls -d /usr/local/lib 2>/dev/null | tail -n 1)) | ||
LDFLAGS += -L/usr/local/lib | ||
endif | ||
ifneq (,$(shell ls -d $(HOME)/local/lib 2>/dev/null | tail -n 1)) | ||
LDFLAGS += -L$(HOME)/local/lib | ||
endif | ||
ifeq ($(shell uname),Darwin) | ||
MACOSX_DEPLOYMENT_TARGET = 11.0 | ||
CFLAGS += -mmacosx-version-min=$(MACOSX_DEPLOYMENT_TARGET) | ||
LDFLAGS += -framework OpenGL -mmacosx-version-min=$(MACOSX_DEPLOYMENT_TARGET) | ||
else | ||
LDFLAGS += -lGL | ||
endif | ||
CPPFLAGS += $(shell sdl2-config --cflags) | ||
LDFLAGS += -lGL4Dummies $(shell sdl2-config --libs) -lSDL2_mixer | ||
all: $(PROGNAME) | ||
$(PROGNAME): $(OBJ) | ||
$(CC) $(OBJ) $(LDFLAGS) -o $(PROGNAME) | ||
%.o: %.c | ||
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ | ||
dist: distdir | ||
$(CHMOD) -R a+r $(distdir) | ||
$(TAR) zcvf $(distdir).tgz $(distdir) | ||
$(RM) -r $(distdir) | ||
zip: distdir | ||
$(CHMOD) -R a+r $(distdir) | ||
$(ZIP) -r $(distdir).zip $(distdir) | ||
$(RM) -r $(distdir) | ||
distdir: $(DISTFILES) | ||
$(RM) -r $(distdir) | ||
$(MKDIR) $(distdir) | ||
$(CHMOD) 777 $(distdir) | ||
$(CP) $(DISTFILES) $(distdir) | ||
doc: $(DOXYFILE) | ||
cat $< | sed -e "s/PROJECT_NAME *=.*/PROJECT_NAME = $(PROGNAME)/" |\ | ||
sed -e "s/PROJECT_NUMBER *=.*/PROJECT_NUMBER = $(VERSION)/" >> $<.new | ||
mv -f $<.new $< | ||
cd documentation && doxygen && cd .. | ||
msvc: $(VSCFILES) | ||
@echo "Now these files ($?) already exist. If you wish to regenerate them, you should first delete them manually." | ||
$(VSCFILES): | ||
@echo "Generating $@ ..." | ||
@cat ../../Windows/templates/gl4dSample$(suffix $@) | sed -e "s/INSERT_PROJECT_NAME/$(PROGNAME)/g" | sed -e "s/INSERT_TARGET_NAME/$(PROGNAME)/" | sed -e "s/INSERT_SOURCE_FILES/$(MSVCSRC)/" > $@ | ||
clean: | ||
@$(RM) -r $(PROGNAME) $(OBJ) *~ $(distdir).tgz $(distdir).zip gmon.out \ | ||
core.* documentation/*~ shaders/*~ documentation/html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
/*!\file animations.c | ||
* | ||
* \brief Votre espace de liberté : c'est ici que vous pouvez ajouter | ||
* vos fonctions de transition et d'animation avant de les faire | ||
* référencées dans le tableau _animations du fichier \ref window.c | ||
* | ||
* Des squelettes d'animations et de transitions sont fournis pour | ||
* comprendre le fonctionnement de la bibliothèque. En bonus des | ||
* exemples dont un fondu en GLSL. | ||
* | ||
* \author Farès BELHADJ, [email protected] | ||
* \date April 12, 2023 | ||
*/ | ||
|
||
#include <GL4D/gl4dh.h> | ||
#include "audioHelper.h" | ||
#include <assert.h> | ||
#include <stdlib.h> | ||
#include <GL4D/gl4dg.h> | ||
#include <SDL_image.h> | ||
|
||
/*!\brief identifiant de la géométrie QUAD GL4Dummies */ | ||
static GLuint _quadId = 0; | ||
|
||
void fondu(void (* a0)(int), void (* a1)(int), Uint32 t, Uint32 et, int state) { | ||
/* INITIALISEZ VOS VARIABLES */ | ||
int vp[4], i; | ||
GLint tId; | ||
static GLuint tex[2], pId; | ||
GLboolean dt; | ||
switch(state) { | ||
case GL4DH_INIT: | ||
/* INITIALISEZ VOTRE TRANSITION (SES VARIABLES <STATIC>s) */ | ||
glGetIntegerv(GL_VIEWPORT, vp); | ||
glGenTextures(2, tex); | ||
for(i = 0; i < 2; i++) { | ||
glBindTexture(GL_TEXTURE_2D, tex[i]); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); | ||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); | ||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, vp[2], vp[3], 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | ||
} | ||
pId = gl4duCreateProgram("<vs>shaders/basic.vs", "<fs>shaders/mix.fs", NULL); | ||
return; | ||
case GL4DH_FREE: | ||
/* LIBERER LA MEMOIRE UTILISEE PAR LES <STATIC>s */ | ||
if(tex[0]) { | ||
glDeleteTextures(2, tex); | ||
tex[0] = tex[1] = 0; | ||
} | ||
return; | ||
case GL4DH_UPDATE_WITH_AUDIO: | ||
/* METTRE A JOUR LES DEUX ANIMATIONS EN FONCTION DU SON */ | ||
if(a0) a0(state); | ||
if(a1) a1(state); | ||
return; | ||
default: /* GL4DH_DRAW */ | ||
/* RECUPERER L'ID DE LA DERNIERE TEXTURE ATTACHEE AU FRAMEBUFFER */ | ||
glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &tId); | ||
/* JOUER LES DEUX ANIMATIONS */ | ||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex[0], 0); | ||
if(a0) a0(state); | ||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex[1], 0); | ||
if(a1) a1(state); | ||
/* MIXER LES DEUX ANIMATIONS */ | ||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tId, 0); | ||
dt = glIsEnabled(GL_DEPTH_TEST); | ||
if(dt) | ||
glDisable(GL_DEPTH_TEST); | ||
glUseProgram(pId); | ||
glActiveTexture(GL_TEXTURE0); | ||
glBindTexture(GL_TEXTURE_2D, tex[0]); | ||
glActiveTexture(GL_TEXTURE1); | ||
glBindTexture(GL_TEXTURE_2D, tex[1]); | ||
if(et / (GLfloat)t > 1) { | ||
fprintf(stderr, "%d-%d -- %f\n", et, t, et / (GLfloat)t); | ||
exit(0); | ||
} | ||
glUniform1f(glGetUniformLocation(pId, "dt"), et / (GLfloat)t); | ||
glUniform1i(glGetUniformLocation(pId, "tex0"), 0); | ||
glUniform1i(glGetUniformLocation(pId, "tex1"), 1); | ||
gl4dgDraw(_quadId); | ||
glActiveTexture(GL_TEXTURE1); | ||
glBindTexture(GL_TEXTURE_2D, 0); | ||
glActiveTexture(GL_TEXTURE0); | ||
glBindTexture(GL_TEXTURE_2D, 0); | ||
if(dt) | ||
glEnable(GL_DEPTH_TEST); | ||
return; | ||
} | ||
} | ||
|
||
void rouge(int state) { | ||
/* INITIALISEZ VOS VARIABLES */ | ||
/* ... */ | ||
switch(state) { | ||
case GL4DH_INIT: | ||
/* INITIALISEZ VOTRE ANIMATION (SES VARIABLES <STATIC>s) */ | ||
return; | ||
case GL4DH_FREE: | ||
/* LIBERER LA MEMOIRE UTILISEE PAR LES <STATIC>s */ | ||
return; | ||
case GL4DH_UPDATE_WITH_AUDIO: | ||
/* METTRE A JOUR VOTRE ANIMATION EN FONCTION DU SON */ | ||
return; | ||
default: /* GL4DH_DRAW */ | ||
/* JOUER L'ANIMATION */ | ||
glClearColor(1.0f, 0.0f, 0.0f, 1.0f); | ||
glClear(GL_COLOR_BUFFER_BIT); | ||
return; | ||
} | ||
} | ||
|
||
void vert(int state) { | ||
/* INITIALISEZ VOS VARIABLES */ | ||
/* ... */ | ||
switch(state) { | ||
case GL4DH_INIT: | ||
/* INITIALISEZ VOTRE ANIMATION (SES VARIABLES <STATIC>s) */ | ||
return; | ||
case GL4DH_FREE: | ||
/* LIBERER LA MEMOIRE UTILISEE PAR LES <STATIC>s */ | ||
return; | ||
case GL4DH_UPDATE_WITH_AUDIO: | ||
/* METTRE A JOUR VOTRE ANIMATION EN FONCTION DU SON */ | ||
return; | ||
default: /* GL4DH_DRAW */ | ||
/* JOUER L'ANIMATION */ | ||
glClearColor(0.0f, 1.0f, 0.0f, 1.0f); | ||
glClear(GL_COLOR_BUFFER_BIT); | ||
return; | ||
} | ||
} | ||
|
||
void bleu(int state) { | ||
/* INITIALISEZ VOS VARIABLES */ | ||
/* ... */ | ||
Sint16 * s; | ||
int l, i; | ||
GLfloat temp; | ||
static GLfloat intensite_de_bleu = 0.0f; | ||
switch(state) { | ||
case GL4DH_INIT: | ||
/* INITIALISEZ VOTRE ANIMATION (SES VARIABLES <STATIC>s) */ | ||
return; | ||
case GL4DH_FREE: | ||
/* LIBERER LA MEMOIRE UTILISEE PAR LES <STATIC>s */ | ||
return; | ||
case GL4DH_UPDATE_WITH_AUDIO: | ||
/* METTRE A JOUR VOTRE ANIMATION EN FONCTION DU SON */ | ||
s = (Sint16 *)ahGetAudioStream(); | ||
l = ahGetAudioStreamLength(); | ||
for(i = 0, temp = 0.0f; i < l / 2; i++) { | ||
temp += abs(s[i]) / (GLfloat)(1 << 15); | ||
} | ||
intensite_de_bleu = temp / (l / 4); | ||
return; | ||
default: /* GL4DH_DRAW */ | ||
/* JOUER L'ANIMATION */ | ||
glClearColor(0.0f, 0.0f, intensite_de_bleu, 1.0f); | ||
glClear(GL_COLOR_BUFFER_BIT); | ||
return; | ||
} | ||
} | ||
|
||
void animationsInit(void) { | ||
if(!_quadId) | ||
_quadId = gl4dgGenQuadf(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/*!\file animations.h | ||
* | ||
* \brief Votre espace de liberté : c'est ici que vous pouvez ajouter | ||
* vos fonctions de transition et d'animation avant de les faire | ||
* référencées dans le tableau _animations du fichier \ref window.c | ||
* | ||
* Des squelettes d'animations et de transitions sont fournis pour | ||
* comprendre le fonctionnement de la bibliothèque. En bonus des | ||
* exemples dont un fondu en GLSL. | ||
* | ||
* \author Farès BELHADJ, [email protected] | ||
* \date April 12, 2023 | ||
*/ | ||
#ifndef _ANIMATIONS_H | ||
|
||
#define _ANIMATIONS_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
extern void fondu(void (* a0)(int), void (* a1)(int), Uint32 t, Uint32 et, int state); | ||
extern void rouge(int state); | ||
extern void vert(int state); | ||
extern void bleu(int state); | ||
extern void animationsInit(void); | ||
/* depuis dancing_cubes.c */ | ||
extern void dancing_cubes(int state); | ||
/* depuis phy.c */ | ||
extern void phy(int state); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/*!\file audioHelper.c | ||
* | ||
* \brief éléments audio pouvant être utiles pour la démo. | ||
* \author Farès BELHADJ, [email protected] | ||
* \date May 5, 2014 - February 26, 2016 | ||
*/ | ||
|
||
#include "audioHelper.h" | ||
|
||
/*!\brief pointeur vers la musique chargée par SDL_Mixer */ | ||
static Mix_Music * _mmusic = NULL; | ||
|
||
/*!\brief pointeur vers le flux audio. | ||
* \see ahGetAudioStream | ||
* \see ahSetAudioStream | ||
*/ | ||
static Uint8 * _audioStream = NULL; | ||
/*!\brief longueur du flux audio. | ||
* \see ahGetAudioStreamLength | ||
* \see ahSetAudioStream | ||
*/ | ||
static int _audioStreamLength = 0; | ||
|
||
/*!\brief renvoie le pointeur vers le flux audio. | ||
* \return le pointeur vers le flux audio. | ||
*/ | ||
Uint8 * ahGetAudioStream(void) { | ||
return _audioStream; | ||
} | ||
|
||
/*!\brief renvoie la longueur du flux audio. | ||
* \return la longueur du flux audio. | ||
*/ | ||
int ahGetAudioStreamLength(void) { | ||
return _audioStreamLength; | ||
} | ||
|
||
/*!\brief met à jour le pointeur vers le flux audio et sa longueur. | ||
*/ | ||
void ahSetAudioStream(Uint8 * audioStream, int audioStreamLength) { | ||
_audioStream = audioStream; | ||
_audioStreamLength = audioStreamLength; | ||
} | ||
|
||
/*!\brief Cette fonction est appelée quand l'audio est joué et met | ||
* dans \a stream les données audio de longueur \a len. | ||
* \param udata pour user data, données passées par l'utilisateur, ici NULL. | ||
* \param stream flux de données audio. | ||
* \param len longueur de \a stream. | ||
*/ | ||
static void mixCallback(void *udata, Uint8 *stream, int len) { | ||
ahSetAudioStream(stream, len); | ||
gl4dhUpdateWithAudio(); | ||
ahSetAudioStream(NULL, 0); | ||
} | ||
|
||
/*!\brief Cette fonction initialise les paramètres SDL_Mixer et charge | ||
* le fichier audio. | ||
*/ | ||
void ahInitAudio(const char * file) { | ||
int mixFlags = MIX_INIT_OGG | MIX_INIT_MP3, res; | ||
res = Mix_Init(mixFlags); | ||
if( (res & mixFlags) != mixFlags ) { | ||
fprintf(stderr, "Mix_Init: Erreur lors de l'initialisation de la bibliotheque SDL_Mixer\n"); | ||
fprintf(stderr, "Mix_Init: %s\n", Mix_GetError()); | ||
exit(-3); | ||
} | ||
if(Mix_OpenAudio(44100, AUDIO_S16LSB, 2, 1024) < 0) | ||
exit(-4); | ||
if(!(_mmusic = Mix_LoadMUS(file))) { | ||
fprintf(stderr, "Erreur lors du Mix_LoadMUS: %s\n", Mix_GetError()); | ||
exit(-5); | ||
} | ||
Mix_SetPostMix(mixCallback, NULL); | ||
if(!Mix_PlayingMusic()) | ||
Mix_PlayMusic(_mmusic, 1); | ||
gl4dhStartingSignal(); | ||
} | ||
|
||
/*!\brief Libère l'audio. | ||
*/ | ||
void ahClean(void) { | ||
if(_mmusic) { | ||
if(Mix_PlayingMusic()) | ||
Mix_HaltMusic(); | ||
Mix_FreeMusic(_mmusic); | ||
_mmusic = NULL; | ||
} | ||
Mix_CloseAudio(); | ||
Mix_Quit(); | ||
} |
Oops, something went wrong.