#include "../includes/animations.h" static GLuint _pId = 0; static GLuint _textTexId = 0; static GLuint _quadId = 0; // Initialize static void init(void); // Draw 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("shaders/credits.vs", "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); 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); }