factorize code

This commit is contained in:
Mylloon 2022-05-15 21:50:40 +02:00
parent 26aeb4fd81
commit 1c885c4819
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 10 additions and 14 deletions

View file

@ -5,15 +5,13 @@
void cube(int etat) { void cube(int etat) {
static GLuint cube = 0, proc_id = 0; static GLuint cube = 0, proc_id = 0;
static GLclampf r = 0, static GLclampf rgb[3] = { 0 };
g = 0,
b = 0;
switch(etat) { switch(etat) {
case GL4DH_INIT: case GL4DH_INIT:
r = rand() / (float)RAND_MAX; for(int i = 0; i < 3; ++i) {
g = rand() / (float)RAND_MAX; rgb[i] = rand() / (float)RAND_MAX;
b = rand() / (float)RAND_MAX; }
cube = gl4dgGenCubef(); cube = gl4dgGenCubef();
proc_id = gl4duCreateProgram("<vs>shaders/cube.vs", "<fs>shaders/cube.fs", NULL); proc_id = gl4duCreateProgram("<vs>shaders/cube.vs", "<fs>shaders/cube.fs", NULL);
@ -44,7 +42,7 @@ void cube(int etat) {
break; break;
case GL4DH_DRAW: case GL4DH_DRAW:
glClearColor(r, g, b, 1.f); glClearColor(rgb[0], rgb[1], rgb[2], 1.f);
static GLfloat cube_rotation = 0; static GLfloat cube_rotation = 0;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(proc_id); glUseProgram(proc_id);

View file

@ -5,15 +5,13 @@
void cube2(int etat) { void cube2(int etat) {
static GLuint cube = 0, proc_id = 0; static GLuint cube = 0, proc_id = 0;
static GLclampf r = 0, static GLclampf rgb[3] = { 0 };
g = 0,
b = 0;
switch(etat) { switch(etat) {
case GL4DH_INIT: case GL4DH_INIT:
r = rand() / (float)RAND_MAX; for(int i = 0; i < 3; ++i) {
g = rand() / (float)RAND_MAX; rgb[i] = rand() / (float)RAND_MAX;
b = rand() / (float)RAND_MAX; }
cube = gl4dgGenCubef(); cube = gl4dgGenCubef();
proc_id = gl4duCreateProgram("<vs>shaders/cube.vs", "<fs>shaders/cube.fs", NULL); proc_id = gl4duCreateProgram("<vs>shaders/cube.vs", "<fs>shaders/cube.fs", NULL);
@ -44,7 +42,7 @@ void cube2(int etat) {
break; break;
case GL4DH_DRAW: case GL4DH_DRAW:
glClearColor(r, g, b, 1.f); glClearColor(rgb[0], rgb[1], rgb[2], 1.f);
static GLfloat cube_rotation = 0; static GLfloat cube_rotation = 0;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(proc_id); glUseProgram(proc_id);