diff --git a/includes/utils.h b/includes/utils.h index 43f0afe..286d8d5 100644 --- a/includes/utils.h +++ b/includes/utils.h @@ -4,6 +4,6 @@ #include // Récupère un delta-temps -double get_dt(void); +double get_dt(double *, GLboolean); #endif diff --git a/src/credits.c b/src/credits.c index 7e44251..949ab31 100644 --- a/src/credits.c +++ b/src/credits.c @@ -60,13 +60,11 @@ static void draw(void) { glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - static Uint32 t0 = -1; - GLfloat t, d; - if ((int)t0 == -1) { - t0 = SDL_GetTicks(); + static double t0 = -1; + if (t0 == -1) { + t0 = gl4dGetElapsedTime(); } - t = (GLfloat)(SDL_GetTicks() - t0) / 1000.f; - d = -1.1f + .25f * t; + GLfloat dt = .25f * (GLfloat)get_dt(&t0, GL_FALSE) - 1.1f; GLfloat ratio = (GLfloat)_dims[0] / (GLfloat)_dims[1]; gl4duBindMatrix(matrix_proj); @@ -76,7 +74,7 @@ static void draw(void) { gl4duBindMatrix(matrix_modview); gl4duLoadIdentityf(); - gl4duTranslatef(0.f, d, -2.f); + gl4duTranslatef(0.f, dt, -2.f); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, _texId); gl4duScalef(1, 0.3f, 1); diff --git a/src/manif.c b/src/manif.c index 3f5d8a3..1426020 100644 --- a/src/manif.c +++ b/src/manif.c @@ -40,6 +40,9 @@ static void init(void) { } static void draw(void) { + static double t0 = 0; + double dt = get_dt(&t0, GL_TRUE); + glClearColor(0.2f, 0.2f, 0.8f, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram(_pId); @@ -47,6 +50,7 @@ static void draw(void) { const GLfloat couleur_plan[] = {0.3f, 0.3f, 0.3f, 1}, couleur_heros[] = {1, 1, 0, 1}; GLint couleur_loc = glGetUniformLocation(_pId, "couleur"); + static double deplacement = 0; const GLfloat lumpos[] = {1, 2, 3, 1}; GLint lum_loc = glGetUniformLocation(_pId, "lumpos"); @@ -78,6 +82,6 @@ static void draw(void) { gl4duSendMatrices(); glUniform4fv(couleur_loc, 1, couleur_heros); gl4dgDraw(_herosId); - + deplacement += 0.4 * M_PI * dt; glUseProgram(0); } diff --git a/src/utils.c b/src/utils.c index e9c181c..e9cae7b 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,9 +1,10 @@ #include "../includes/utils.h" -double get_dt(void) { - static double t0 = 0.0f; - double t = gl4dGetElapsedTime(), dt = (t - t0) / 1000.0; - t0 = t; +double get_dt(double *t0, GLboolean override_t0) { + double t = gl4dGetElapsedTime(), dt = (t - *t0) / 1000.0; + if (override_t0) { + *t0 = t; + } return dt; }