use functions

This commit is contained in:
Mylloon 2023-05-03 16:08:08 +02:00
parent eadb04f159
commit a736dca50e
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 68 additions and 54 deletions

View file

@ -1,17 +1,22 @@
#include "../includes/animations.h"
static void init();
static void draw();
void credits(int state) {
switch (state) {
case GL4DH_INIT:
init();
break;
case GL4DH_DRAW:
break;
case GL4DH_FREE:
draw();
break;
default:
break;
}
}
static void init() {}
static void draw() {}

View file

@ -1,66 +1,75 @@
#include "../includes/animations.h"
void cube(int, int);
static GLuint _pId = 0;
static GLuint _quadId = 0;
static void init();
static void draw();
void lights(int state) {
static GLuint quadId = 0;
static GLuint pId = 0;
switch (state) {
case GL4DH_INIT:
quadId = gl4dgGenQuadf();
pId = gl4duCreateProgram("<vs>shaders/lights.vs", "<fs>shaders/lights.fs",
NULL);
gl4duGenMatrix(GL_FLOAT, "proj");
gl4duGenMatrix(GL_FLOAT, "mod");
gl4duGenMatrix(GL_FLOAT, "view");
glEnable(GL_DEPTH_TEST);
init();
break;
case GL4DH_DRAW:
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
static GLdouble lumloc = 0.;
// clang-format off
GLfloat rouge[] = {1.f, 0.f, 0.f, 1.f},
blanc[] = {1.f, 1.f, 1.f, 1.f},
lumpos0[] = {4.f * (float)sin(lumloc), 0.f, 1.1f, 1.f},
lumpos[4],
*mat,
ratio = (GLfloat)_dims[0] / (GLfloat)_dims[1];
// clang-format on
// Setup
gl4duBindMatrix("proj");
gl4duLoadIdentityf(); // TODO: ça bug??
gl4duFrustumf(-ratio, ratio, -1, 1, 2, 100);
// Scene
gl4duBindMatrix("view");
gl4duLoadIdentityf();
gl4duLookAtf(0, 0, 4.0f, 0, 0, 0, 0.0f, 1.0f, 0);
mat = (GLfloat *)gl4duGetMatrixData();
MMAT4XVEC4(lumpos, mat, lumpos0);
gl4duBindMatrix("mod");
gl4duLoadIdentityf();
glUseProgram(pId);
gl4duSendMatrices();
glUniform4fv(glGetUniformLocation(pId, "scolor"), 1, rouge);
glUniform4fv(glGetUniformLocation(pId, "lcolor"), 1, blanc);
glUniform4fv(glGetUniformLocation(pId, "lumpos"), 1, lumpos);
gl4dgDraw(quadId);
glUseProgram(0);
draw();
break;
default:
break;
}
}
static void init() {
_quadId = gl4dgGenQuadf();
_pId = gl4duCreateProgram("<vs>shaders/lights.vs", "<fs>shaders/lights.fs",
NULL);
gl4duGenMatrix(GL_FLOAT, "proj");
gl4duGenMatrix(GL_FLOAT, "mod");
gl4duGenMatrix(GL_FLOAT, "view");
glEnable(GL_DEPTH_TEST);
}
static void draw() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
static GLdouble lumloc = 0.;
// clang-format off
GLfloat rouge[] = {1.f, 0.f, 0.f, 1.f},
blanc[] = {1.f, 1.f, 1.f, 1.f},
lumpos0[] = {4.f * (float)sin(lumloc), 0.f, 1.1f, 1.f},
lumpos[4],
*mat,
ratio = (GLfloat)_dims[0] / (GLfloat)_dims[1];
// clang-format on
// Setup
gl4duBindMatrix("proj");
gl4duLoadIdentityf();
gl4duFrustumf(-ratio, ratio, -1, 1, 2, 100);
// Scene
gl4duBindMatrix("view");
gl4duLoadIdentityf();
gl4duLookAtf(0, 0, 4.0f, 0, 0, 0, 0.0f, 1.0f, 0);
mat = (GLfloat *)gl4duGetMatrixData();
MMAT4XVEC4(lumpos, mat, lumpos0);
gl4duBindMatrix("mod");
gl4duLoadIdentityf();
glUseProgram(_pId);
gl4duSendMatrices();
glUniform4fv(glGetUniformLocation(_pId, "scolor"), 1, rouge);
glUniform4fv(glGetUniformLocation(_pId, "lcolor"), 1, blanc);
glUniform4fv(glGetUniformLocation(_pId, "lumpos"), 1, lumpos);
gl4dgDraw(_quadId);
glUseProgram(0);
}