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

View file

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