This repository has been archived on 2023-05-27. You can view files and clone it, but cannot push or open issues or pull requests.
api8/src/credits.c

86 lines
1.9 KiB
C

#include "../includes/animations.h"
static GLuint _pId = 0;
static GLuint _textTexId = 0;
static GLuint _quadId = 0;
static void init(void);
static void draw(void);
void credits(int state) {
switch (state) {
case GL4DH_INIT:
init();
break;
case GL4DH_DRAW:
draw();
break;
default:
break;
}
}
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();
// Charge la police
TTF_Font *font = NULL;
if (initFont(&font, "fonts/Instrument.ttf", 100)) {
exit(1);
}
// 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);
}
// Libère la police de la mémoire
freeFont(font);
}
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);
gl4duBindMatrix("modview");
gl4duLoadIdentityf();
gl4duTranslatef(0.f, d - 1.5f, -2.f);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, _textTexId);
gl4duScalef(1.f, .3f, 1.f);
glUseProgram(_pId);
gl4duSendMatrices();
glUniform1i(glGetUniformLocation(_pId, "inv"), 1);
glUniform1i(glGetUniformLocation(_pId, "tex"), 0);
gl4dgDraw(_quadId);
glUseProgram(0);
}