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;
|
|
|
|
|
2023-05-03 16:08:33 +02:00
|
|
|
// Initialize
|
2023-05-03 17:24:54 +02:00
|
|
|
static void init(void);
|
2023-05-03 16:08:33 +02:00
|
|
|
|
|
|
|
// Draw
|
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();
|
|
|
|
|
|
|
|
// Font
|
|
|
|
char *text = " CRÉDITS\n\n"
|
|
|
|
"Concours API8 — 7 édition\n"
|
|
|
|
"Font: fontesk et fontsquirrel\n"
|
|
|
|
"Librairies: GL4D, SDL2 et extensions";
|
|
|
|
char *fontName = "fonts/Instrument.ttf";
|
|
|
|
|
|
|
|
SDL_Color c = {255, 255, 255, 255};
|
|
|
|
SDL_Surface *d, *s;
|
|
|
|
TTF_Font *font = NULL;
|
|
|
|
|
|
|
|
if (TTF_Init() == -1) {
|
|
|
|
fprintf(stderr, "Erreur TTF : %s\n", TTF_GetError());
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
glGenTextures(1, &_textTexId);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, _textTexId);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
|
|
|
|
if (!(font = TTF_OpenFont(fontName, 100))) {
|
|
|
|
fprintf(stderr, "Erreur TTF : %s\n", TTF_GetError());
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((d = TTF_RenderUTF8_Blended_Wrapped(font, text, c, 0)) == NULL) {
|
|
|
|
TTF_CloseFont(font);
|
|
|
|
fprintf(stderr, "Erreur TTF : RenderText\n");
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert((s = SDL_CreateRGBSurface(0, d->w, d->h, 32, R_MASK, G_MASK, B_MASK,
|
|
|
|
A_MASK)));
|
|
|
|
SDL_BlitSurface(d, NULL, s, NULL);
|
|
|
|
SDL_FreeSurface(d);
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, _textTexId);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, s->w, s->h, 0, GL_RGBA,
|
|
|
|
GL_UNSIGNED_BYTE, s->pixels);
|
|
|
|
|
|
|
|
SDL_FreeSurface(s);
|
|
|
|
TTF_CloseFont(font);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
gl4duTranslatef(0.f, d, -2.f);
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, _textTexId);
|
|
|
|
gl4duScalef(.5f, .1f, .5f);
|
|
|
|
|
|
|
|
glUseProgram(_pId);
|
|
|
|
gl4duSendMatrices();
|
|
|
|
|
|
|
|
glUniform1i(glGetUniformLocation(_pId, "inv"), 1);
|
|
|
|
glUniform1i(glGetUniformLocation(_pId, "tex"), 0);
|
|
|
|
gl4dgDraw(_quadId);
|
|
|
|
|
|
|
|
glUseProgram(0);
|
|
|
|
}
|