From 1c885c4819ff83fc80e37be3c17ec0000004c964 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 15 May 2022 21:50:40 +0200 Subject: [PATCH] factorize code --- src/cube.c | 12 +++++------- src/cube2.c | 12 +++++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/cube.c b/src/cube.c index 533950f..8fbffb0 100644 --- a/src/cube.c +++ b/src/cube.c @@ -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("shaders/cube.vs", "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); diff --git a/src/cube2.c b/src/cube2.c index c798ef2..4e68de1 100644 --- a/src/cube2.c +++ b/src/cube2.c @@ -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("shaders/cube.vs", "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);