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" #include "../includes/animations.h"
static void init();
static void draw();
void credits(int state) { void credits(int state) {
switch (state) { switch (state) {
case GL4DH_INIT: case GL4DH_INIT:
init();
break; break;
case GL4DH_DRAW: case GL4DH_DRAW:
break; draw();
case GL4DH_FREE:
break; break;
default: default:
break; break;
} }
} }
static void init() {}
static void draw() {}

View file

@ -1,15 +1,29 @@
#include "../includes/animations.h" #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) { void lights(int state) {
static GLuint quadId = 0;
static GLuint pId = 0;
switch (state) { switch (state) {
case GL4DH_INIT: case GL4DH_INIT:
quadId = gl4dgGenQuadf(); init();
pId = gl4duCreateProgram("<vs>shaders/lights.vs", "<fs>shaders/lights.fs", break;
case GL4DH_DRAW:
draw();
break;
default:
break;
}
}
static void init() {
_quadId = gl4dgGenQuadf();
_pId = gl4duCreateProgram("<vs>shaders/lights.vs", "<fs>shaders/lights.fs",
NULL); NULL);
gl4duGenMatrix(GL_FLOAT, "proj"); gl4duGenMatrix(GL_FLOAT, "proj");
@ -17,9 +31,9 @@ void lights(int state) {
gl4duGenMatrix(GL_FLOAT, "view"); gl4duGenMatrix(GL_FLOAT, "view");
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
break; }
case GL4DH_DRAW: static void draw() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -35,7 +49,7 @@ void lights(int state) {
// Setup // Setup
gl4duBindMatrix("proj"); gl4duBindMatrix("proj");
gl4duLoadIdentityf(); // TODO: ça bug?? gl4duLoadIdentityf();
gl4duFrustumf(-ratio, ratio, -1, 1, 2, 100); gl4duFrustumf(-ratio, ratio, -1, 1, 2, 100);
// Scene // Scene
@ -49,18 +63,13 @@ void lights(int state) {
gl4duBindMatrix("mod"); gl4duBindMatrix("mod");
gl4duLoadIdentityf(); gl4duLoadIdentityf();
glUseProgram(pId); glUseProgram(_pId);
gl4duSendMatrices(); gl4duSendMatrices();
glUniform4fv(glGetUniformLocation(pId, "scolor"), 1, rouge); glUniform4fv(glGetUniformLocation(_pId, "scolor"), 1, rouge);
glUniform4fv(glGetUniformLocation(pId, "lcolor"), 1, blanc); glUniform4fv(glGetUniformLocation(_pId, "lcolor"), 1, blanc);
glUniform4fv(glGetUniformLocation(pId, "lumpos"), 1, lumpos); glUniform4fv(glGetUniformLocation(_pId, "lumpos"), 1, lumpos);
gl4dgDraw(quadId); gl4dgDraw(_quadId);
glUseProgram(0); glUseProgram(0);
break;
default:
break;
}
} }