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/manif.c

86 lines
2.1 KiB
C
Raw Normal View History

2023-05-08 09:07:48 +02:00
#include "../includes/animations.h"
static GLuint _pId = 0;
2023-05-08 10:23:45 +02:00
static GLuint _planId = 0;
2023-05-08 10:38:45 +02:00
static GLuint _herosId = 0;
static const char matrix_proj[] = "proj";
static const char matrix_model[] = "model";
static const char matrix_view[] = "view";
2023-05-08 09:07:48 +02:00
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) {
2023-05-08 10:23:45 +02:00
_planId = gl4dgGenQuadf();
2023-05-08 10:38:45 +02:00
_herosId = gl4dgGenConef(3, GL_FALSE);
2023-05-08 09:08:09 +02:00
_pId =
gl4duCreateProgram("<vs>shaders/manif.vs", "<fs>shaders/manif.fs", NULL);
2023-05-08 09:07:48 +02:00
2023-05-08 10:38:45 +02:00
gl4duGenMatrix(GL_FLOAT, matrix_proj);
gl4duGenMatrix(GL_FLOAT, matrix_model);
gl4duGenMatrix(GL_FLOAT, matrix_view);
2023-05-08 09:07:48 +02:00
glEnable(GL_DEPTH_TEST);
}
static void draw(void) {
2023-05-08 13:41:32 +02:00
static double t0 = 0;
double dt = get_dt(&t0, GL_TRUE);
2023-05-08 10:23:45 +02:00
glClearColor(0.2f, 0.2f, 0.8f, 1);
2023-05-08 09:07:48 +02:00
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2023-05-08 10:23:45 +02:00
glUseProgram(_pId);
2023-05-08 09:07:48 +02:00
2023-05-08 11:29:12 +02:00
const GLfloat couleur_plan[] = {0.3f, 0.3f, 0.3f, 1},
2023-05-08 12:16:29 +02:00
couleur_heros[] = {1, 1, 0, 1};
2023-05-08 15:06:42 +02:00
GLint couleur_gpu = glGetUniformLocation(_pId, "couleur");
2023-05-08 13:41:32 +02:00
static double deplacement = 0;
2023-05-08 11:29:12 +02:00
2023-05-08 15:06:42 +02:00
const GLfloat lumpos[] = {1, (GLfloat)(2 + 2 * sin(deplacement)), 1, 1};
glUniform4fv(glGetUniformLocation(_pId, "lumpos"), 1, lumpos);
2023-05-08 10:38:45 +02:00
2023-05-08 15:06:42 +02:00
bindAndLoadf(matrix_proj);
2023-05-08 10:23:45 +02:00
GLfloat ratio = (GLfloat)_dims[0] / (GLfloat)_dims[1];
gl4duFrustumf(-1, 1, -ratio, ratio, 1, 1000);
2023-05-08 15:06:42 +02:00
bindAndLoadf(matrix_view);
2023-05-08 10:23:45 +02:00
const GLfloat distance = 2;
2023-05-08 15:06:42 +02:00
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);
2023-05-08 10:23:45 +02:00
2023-05-08 15:06:42 +02:00
bindAndLoadf(matrix_model);
2023-05-08 10:23:45 +02:00
gl4duRotatef(-90, 1, 0, 0);
gl4duScalef(4 * distance, 2 * distance, 1);
gl4duSendMatrices();
2023-05-08 15:06:42 +02:00
glUniform4fv(couleur_gpu, 1, couleur_plan);
2023-05-08 10:23:45 +02:00
gl4dgDraw(_planId);
2023-05-08 09:07:48 +02:00
2023-05-08 15:06:42 +02:00
bindAndLoadf(matrix_model);
2023-05-08 12:27:29 +02:00
gl4duScalef(1, 1.5, 1);
2023-05-08 15:06:42 +02:00
gl4duRotatef((GLfloat)(180 * deplacement / M_PI), 0, 1, 0);
2023-05-08 10:38:45 +02:00
gl4duSendMatrices();
2023-05-08 15:06:42 +02:00
glUniform4fv(couleur_gpu, 1, couleur_heros);
2023-05-08 10:38:45 +02:00
gl4dgDraw(_herosId);
2023-05-08 13:41:32 +02:00
deplacement += 0.4 * M_PI * dt;
2023-05-08 09:07:48 +02:00
glUseProgram(0);
}