2023-05-03 12:22:42 +02:00
|
|
|
#include "../includes/animations.h"
|
|
|
|
|
2023-05-03 17:24:54 +02:00
|
|
|
static GLuint _pId = 0;
|
|
|
|
static GLuint _textTexId = 0;
|
|
|
|
static GLuint _quadId = 0;
|
|
|
|
|
|
|
|
static void init(void);
|
2023-05-03 16:08:33 +02:00
|
|
|
|
2023-05-03 17:24:54 +02:00
|
|
|
static void draw(void);
|
2023-05-03 16:08:08 +02:00
|
|
|
|
2023-05-03 12:22:42 +02:00
|
|
|
void credits(int state) {
|
|
|
|
switch (state) {
|
|
|
|
case GL4DH_INIT:
|
2023-05-03 16:08:08 +02:00
|
|
|
init();
|
2023-05-03 12:22:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GL4DH_DRAW:
|
2023-05-03 16:08:08 +02:00
|
|
|
draw();
|
2023-05-03 12:22:42 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-05-03 16:08:08 +02:00
|
|
|
|
2023-05-03 17:24:54 +02:00
|
|
|
static void init(void) {
|
|
|
|
_pId = gl4duCreateProgram("<vs>shaders/credits.vs", "<fs>shaders/credits.fs",
|
|
|
|
NULL);
|
|
|
|
gl4duGenMatrix(GL_FLOAT, "modview");
|
|
|
|
gl4duGenMatrix(GL_FLOAT, "proj");
|
|
|
|
_quadId = gl4dgGenQuadf();
|
|
|
|
|
2023-05-03 21:07:59 +02:00
|
|
|
// Charge la police
|
2023-05-03 17:24:54 +02:00
|
|
|
TTF_Font *font = NULL;
|
2023-05-03 21:07:59 +02:00
|
|
|
if (initFont(&font, "fonts/Instrument.ttf", 100)) {
|
|
|
|
exit(1);
|
2023-05-03 17:24:54 +02:00
|
|
|
}
|
|
|
|
|
2023-05-03 21:07:59 +02:00
|
|
|
// Ecrit avec la police sur une texture
|
|
|
|
if (writeText(&_textTexId, font,
|
|
|
|
" CRÉDITS\n\n"
|
|
|
|
"Concours API8 — 7e édition\n"
|
|
|
|
"Font: fontesk et fontsquirrel\n"
|
|
|
|
"Audio: beepbox\n"
|
|
|
|
"Librairies: GL4D, SDL2 et extensions",
|
|
|
|
(SDL_Color){255, 255, 255, 255})) {
|
|
|
|
exit(1);
|
2023-05-03 17:24:54 +02:00
|
|
|
}
|
|
|
|
|
2023-05-03 21:07:59 +02:00
|
|
|
// Libère la police de la mémoire
|
|
|
|
freeFont(font);
|
2023-05-03 17:24:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void draw(void) {
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
static Uint32 t0 = -1;
|
|
|
|
GLfloat t, d;
|
|
|
|
if (t0 < 0.0f)
|
|
|
|
t0 = SDL_GetTicks();
|
|
|
|
t = (GLfloat)(SDL_GetTicks() - t0) / 1000.f;
|
|
|
|
d = -1.1f + .25f * t;
|
|
|
|
|
|
|
|
GLfloat ratio = (GLfloat)_dims[0] / (GLfloat)_dims[1];
|
|
|
|
gl4duBindMatrix("proj");
|
|
|
|
gl4duLoadIdentityf();
|
|
|
|
gl4duFrustumf(-ratio, ratio, -1, 1, 2, 100);
|
2023-05-03 16:08:33 +02:00
|
|
|
|
2023-05-03 17:24:54 +02:00
|
|
|
gl4duBindMatrix("modview");
|
|
|
|
gl4duLoadIdentityf();
|
|
|
|
|
2023-05-03 17:52:34 +02:00
|
|
|
gl4duTranslatef(0.f, d - 1.5f, -2.f);
|
2023-05-03 17:24:54 +02:00
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, _textTexId);
|
2023-05-03 17:52:34 +02:00
|
|
|
gl4duScalef(1.f, .3f, 1.f);
|
2023-05-03 17:24:54 +02:00
|
|
|
|
|
|
|
glUseProgram(_pId);
|
|
|
|
gl4duSendMatrices();
|
|
|
|
|
|
|
|
glUniform1i(glGetUniformLocation(_pId, "inv"), 1);
|
|
|
|
glUniform1i(glGetUniformLocation(_pId, "tex"), 0);
|
|
|
|
gl4dgDraw(_quadId);
|
|
|
|
|
|
|
|
glUseProgram(0);
|
|
|
|
}
|