#include "../includes/animations.h" static GLuint _pId = 0; static GLuint _planId = 0; static GLuint _herosId = 0; static const char matrix_proj[] = "proj"; static const char matrix_model[] = "model"; static const char matrix_view[] = "view"; static void init(void); static void draw(void); void manif(int state) { switch (state) { case GL4DH_INIT: init(); break; case GL4DH_DRAW: draw(); break; default: break; } } static void init(void) { _planId = gl4dgGenQuadf(); _herosId = gl4dgGenConef(3, GL_FALSE); _pId = gl4duCreateProgram("shaders/manif.vs", "shaders/manif.fs", NULL); gl4duGenMatrix(GL_FLOAT, matrix_proj); gl4duGenMatrix(GL_FLOAT, matrix_model); gl4duGenMatrix(GL_FLOAT, matrix_view); glEnable(GL_DEPTH_TEST); } 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); const GLfloat couleur_plan[] = {0.3f, 0.3f, 0.3f, 1}, couleur_heros[] = {1, 1, 0, 1}; GLint couleur_gpu = glGetUniformLocation(_pId, "couleur"); static double deplacement = 0; const GLfloat lumpos[] = {1, (GLfloat)(2 + 2 * sin(deplacement)), 1, 1}; glUniform4fv(glGetUniformLocation(_pId, "lumpos"), 1, lumpos); bindAndLoadf(matrix_proj); GLfloat ratio = (GLfloat)_dims[0] / (GLfloat)_dims[1]; gl4duFrustumf(-1, 1, -ratio, ratio, 1, 1000); bindAndLoadf(matrix_view); const GLfloat distance = 2; const GLfloat eye[3] = {0, distance, distance}; gl4duLookAtf(eye[0], eye[1], eye[2], 0, 0, 0, 0, 1, 0); glUniform4fv(glGetUniformLocation(_pId, "camerapos"), 1, eye); bindAndLoadf(matrix_model); gl4duRotatef(-90, 1, 0, 0); gl4duScalef(4 * distance, 2 * distance, 1); gl4duSendMatrices(); glUniform4fv(couleur_gpu, 1, couleur_plan); gl4dgDraw(_planId); bindAndLoadf(matrix_model); gl4duScalef(1, 1.5, 1); gl4duRotatef((GLfloat)(180 * deplacement / M_PI), 0, 1, 0); gl4duSendMatrices(); glUniform4fv(couleur_gpu, 1, couleur_heros); gl4dgDraw(_herosId); deplacement += 0.4 * M_PI * dt; glUseProgram(0); }