diff --git a/include/graphics_compute.h b/include/buffers.h similarity index 100% rename from include/graphics_compute.h rename to include/buffers.h diff --git a/include/graphics_control.h b/include/graphics.h similarity index 98% rename from include/graphics_control.h rename to include/graphics.h index 03323a4..f1695a1 100644 --- a/include/graphics_control.h +++ b/include/graphics.h @@ -5,6 +5,7 @@ * * Copyright (C) 2023 Arthur Menges * Copyright (C) 2023 Adrien Bourmault + * Copyright (C) 2023 Jean Sirmai * * This file is part of Gem-graph. * diff --git a/include/space_2D.h b/include/space_2D.h index 917a844..7a6dc44 100644 --- a/include/space_2D.h +++ b/include/space_2D.h @@ -29,4 +29,5 @@ bool compute_space_2D(int state_size, GLfloat *vertex_base, GLfloat *color_base, GLubyte *line_ndx, - bool pref_mark_unit_space_zero, int dgap); + bool pref_mark_unit_space_first, + bool pref_mark_unit_space_last); diff --git a/include/space_3D.h b/include/space_3D.h index db14f3c..6a49829 100644 --- a/include/space_3D.h +++ b/include/space_3D.h @@ -29,4 +29,5 @@ bool compute_space_3D(int state_size, GLfloat *vertex_base, GLfloat *color_base, GLubyte *line_ndx, - bool pref_mark_unit_space_zero, int dgap); + bool pref_mark_unit_space_first, + bool pref_mark_unit_space_last); diff --git a/src/graphics/graphics_compute.c b/src/graphics/buffers.c similarity index 97% rename from src/graphics/graphics_compute.c rename to src/graphics/buffers.c index de83d3c..c379547 100644 --- a/src/graphics/graphics_compute.c +++ b/src/graphics/buffers.c @@ -4,6 +4,7 @@ * Desc: OpenGL utils header * * Copyright (C) 2023 Jean Sirmai + * Copyleft (something) ( ;- )) Isn't that fun ?! ----------------,cbF@^@ââ63-OPM,FJ&_(_((T^RQJn||lpv)=à)o ----------------------------------------------------- * * This file is part of Gem-graph. * @@ -39,8 +40,8 @@ #include "../../include/base.h" #include "../../include/ui.h" -#include "../../include/graphics_control.h" -#include "../../include/graphics_compute.h" +#include "../../include/graphics.h" +#include "../../include/buffers.h" #include "../../include/space_2D.h" #include "../../include/space_3D.h" #include "../../include/arrow_2D.h" @@ -70,7 +71,7 @@ int graphics_compute_lines(int line_indices_nb, vertex_nb = (state_size + 1) * 12 + arrows_nb * 15; colors_nb = (state_size + 1) * 12 + arrows_nb * 0; // TODO // lines_nb = (2 + state_size) + (arrows_nb * 3); // cas 2D - lines_nb = (4 + state_size * 4) + (arrows_nb * 8) + 2; // + 2; pour les 2 diagonales + lines_nb = (4 + state_size * 4) + (arrows_nb * 8) + 4; // + 4; pour les 4 diagonales (29/6/2023 pour voir) //// plans_nb = 8; //(4 + state_size * 4) + (arrows_nb * 8) + 2; // bhuingfyunfyuguinlgi svbysbubsyu qvyqytqujtvcttcef line_indices_nb = lines_nb * 2; @@ -100,7 +101,7 @@ int graphics_compute_lines(int line_indices_nb, } compute_space_3D(state_size, vertex_base, color_base, line_ndx, - 0,4); // patch provisoire + 0,0); // patch provisoire // pref_mark_unit_space_zero, dgap){ vgap += (12 * state_size); igap += state_size * 8 + 8; cgap += (12 * state_size); @@ -256,7 +257,7 @@ int graphics_compute_plans(int plan_indices_nb, // assert(k + 8 < line_indices_nb); assert(k + 16 < line_indices_nb); compute_space_3D(state_size, vertex_base, color_base, plan_ndx, - 0,4); // patch provisoire + 0,0); // patch provisoire //pref_mark_unit_space_zero, dgap){ vgap += (12 * state_size); igap += state_size * 8 + 8; cgap += (12 * state_size); diff --git a/src/graphics/graphics_control.c b/src/graphics/graphics.c similarity index 90% rename from src/graphics/graphics_control.c rename to src/graphics/graphics.c index 51d19fc..28d923b 100644 --- a/src/graphics/graphics_control.c +++ b/src/graphics/graphics.c @@ -38,7 +38,7 @@ #include "../../include/base.h" #include "../../include/ui.h" -#include "../../include/graphics_control.h" +#include "../../include/graphics.h" #include "../../include/space_2D.h" #include "../../include/space_3D.h" #include "../../include/arrow_2D.h" @@ -493,9 +493,12 @@ int colors_nb = 0; int lines_nb = 0; int plans_nb = 0; int arrows_nb = 0; -bool pref_3D_xor_2D_space = 0; // default view == 0 == 3D -bool pref_3D_xor_2D_arrows = 0; // default view == 0 == 3D -bool pref_mark_unit_space_zero = 0; // default == 0 == no mark + +bool pref_3D_xor_2D_space = 0; // default view == 0 == 3D +bool pref_3D_xor_2D_arrows = 0; // default view == 0 == 3D +bool pref_mark_unit_space_first = 0; // default == 0 == no mark +bool pref_mark_unit_space_last = 0; // default == 0 == no mark +bool pref_background_color = 0; // don't know yet... /* -------------------------------------------------------------------------- */ @@ -504,11 +507,13 @@ static void get_model_data_and_user_preferences(){ // { 1, 1, 0, 1, 2, 1, 1, 1, 10, 1, 2, 11, 1, 1, 20, 1, 2, 21 }; dim = 1; - state_size = 9; // 2 < state_size < 32 + state_size = 8; // 2 < state_size < 32 arrows_nb = 4; // assert : leur emplacement doit être fonction de state_size pref_3D_xor_2D_space = 0; // default == 0 == 3D pref_3D_xor_2D_arrows = 1; // default == 0 == 3D - pref_mark_unit_space_zero = 1; // default == 0 == no mark + pref_mark_unit_space_first = 1; // default == 0 == no mark + pref_mark_unit_space_last = 1; // default == 0 == no mark + pref_background_color = 0; // TODO } static void compute_vertex_colors_lines_plans_nb(int dim, @@ -516,16 +521,19 @@ static void compute_vertex_colors_lines_plans_nb(int dim, int arrows_nb, bool pref_3D_xor_2D_space, bool pref_3D_xor_2D_arrows, - bool pref_mark_unit_space_zero, + bool pref_mark_unit_space_first, + bool pref_mark_unit_space_last, struct gl_area_entry *entry){ + if (pref_3D_xor_2D_space) vertex_nb = (state_size + 1) * 6 + arrows_nb * 9; // case 2D else vertex_nb = (state_size + 1) * 12 + arrows_nb * 15; // case 3D - if (pref_3D_xor_2D_space) lines_nb = (2 + state_size) + (arrows_nb * 3); // case 2D + if (pref_3D_xor_2D_space) lines_nb = (2 + state_size) + (arrows_nb * 3); // case 2D else lines_nb = (4 + state_size * 4) + (arrows_nb * 8); // case 3D - if (pref_mark_unit_space_zero) lines_nb += 2; // 2 diagonal lines - // + if (pref_mark_unit_space_first) lines_nb += 2; // 2 diagonal lines + if (pref_mark_unit_space_last) lines_nb += 2; // 2 diagonal lines + plans_nb = 8; // (4 + state_size * 4) + (arrows_nb * 8) + 2; entry->line_indices_nb = lines_nb * 2; @@ -535,10 +543,10 @@ static void compute_vertex_colors_lines_plans_nb(int dim, assert(state_size * 6 < vertex_nb); assert(state_size * 6 + 5 < vertex_nb); - printf("Prefer : mark_unit_space_zero = %d pref_3D_xor_2D_space = %d state_size = %d\n", - pref_mark_unit_space_zero, pref_3D_xor_2D_space, state_size); + printf("Prefer : mark_unit_space_first = %d mark_unit_space_last = %d 3D_xor_2D_space = %d\n", + pref_mark_unit_space_first, pref_mark_unit_space_last, pref_3D_xor_2D_space); - printf("Initialization of buffers with %u line_ndx, %u vertices and %u colors & state_size = %d\n", + printf("Initialization of buffers with %u line_ndx, %u vertices, %u colors. state_size = %d\n", entry->line_indices_nb, vertex_nb, colors_nb, state_size); } @@ -558,7 +566,8 @@ void graphics_init_buffers(const void *gl_area) compute_vertex_colors_lines_plans_nb(dim, state_size, arrows_nb, pref_3D_xor_2D_space, pref_3D_xor_2D_arrows, - pref_mark_unit_space_zero, + pref_mark_unit_space_first, + pref_mark_unit_space_last, entry); // g_malloc @@ -570,7 +579,8 @@ void graphics_init_buffers(const void *gl_area) int vgap = 0, igap = 0, cgap = 0, dgap = 0; - if (pref_mark_unit_space_zero) dgap = 4; // 4 vertices for 2 diagonal lines + if (pref_mark_unit_space_first) dgap += 4; // 4 vertices for 2 diagonal lines + if (pref_mark_unit_space_last) dgap += 4; // 4 vertices for 2 diagonal lines vgap += (6 * state_size); igap += state_size * 2 + dgap; cgap += (6 * state_size); @@ -578,18 +588,24 @@ void graphics_init_buffers(const void *gl_area) if (pref_3D_xor_2D_space) compute_space_2D(state_size, vertex_base, color_base, line_ndx, - pref_mark_unit_space_zero, dgap); + pref_mark_unit_space_first, + pref_mark_unit_space_last); else compute_space_3D(state_size, vertex_base, color_base, line_ndx, - pref_mark_unit_space_zero, dgap); + pref_mark_unit_space_first, + pref_mark_unit_space_last); - for (int k = 0; k < state_size; k++){ + if (pref_3D_xor_2D_space) for (int k = 0; k < state_size; k++) { + assert(k * 6 < vertex_nb); assert(k * 6 + 5 < vertex_nb); + assert(k * 6 < colors_nb); assert(k * 6 + 5 < colors_nb); + assert(k + 4 < entry->line_indices_nb); assert(k + 8 < entry->line_indices_nb); // TODO check this line ! + } else for (int k = 0; k < state_size; k++) { assert(k * 12 < vertex_nb); assert(k * 12 + 11 < vertex_nb); assert(k * 12 < colors_nb); assert(k * 12 + 11 < colors_nb); - assert(k + 8 < entry->line_indices_nb); assert(k + 16 < entry->line_indices_nb); - } + assert(k + 8 < entry->line_indices_nb); assert(k + 16 < entry->line_indices_nb); // TODO check this line ! + } assert(vgap < vertex_nb); assert(vgap + 9 < vertex_nb); assert(igap < entry->line_indices_nb); assert(igap + 5 < entry->line_indices_nb); @@ -667,7 +683,8 @@ void graphics_draw(const void *gl_area) /* Use our shaders */ glUseProgram(entry->program); - glClearColor(0, 0, 0, 0.2f); // glClearColor(0.3f, 0, 0, 0.8f); + if (pref_background_color == 0) glClearColor(0, 0, 0, 0.4f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Update the "mvp" matrix we use in the shader */ diff --git a/src/graphics/space_2D.c b/src/graphics/space_2D.c index 0f905a1..61b7e0a 100644 --- a/src/graphics/space_2D.c +++ b/src/graphics/space_2D.c @@ -30,7 +30,9 @@ bool compute_space_2D(int state_size, GLfloat *vertex_base, GLfloat *color_base, GLubyte *line_ndx, - bool pref_mark_unit_space_zero, int dgap){ + bool pref_mark_unit_space_first, + bool pref_mark_unit_space_last) +{ float x = 0; // for (int k = 0; k < state_size + 1; k++) <=> + 1 @@ -52,8 +54,32 @@ bool compute_space_2D(int state_size, *(vertex_base + k * 6 + 3) = - x; *(vertex_base + k * 6 + 4) = - 1.0f / state_size; *(vertex_base + k * 6 + 5) = 0.0f; + + *(color_base + k * 6 + 0) = 1; + *(color_base + k * 6 + 1) = 0; + *(color_base + k * 6 + 2) = 0; + + *(color_base + k * 6 + 3) = 1; + *(color_base + k * 6 + 4) = 1; + *(color_base + k * 6 + 5) = 0; } + *(color_base + 0) = 0; + *(color_base + 1) = 0; + *(color_base + 2) = 0; + + *(color_base + 3) = 1; + *(color_base + 4) = 1; + *(color_base + 5) = 1; + + *(color_base + (state_size - 1) * 6 + 0) = 1; + *(color_base + (state_size - 1) * 6 + 1) = 1; + *(color_base + (state_size - 1) * 6 + 2) = 1; + + *(color_base + (state_size - 1) * 6 + 3) = 0; + *(color_base + (state_size - 1) * 6 + 4) = 0; + *(color_base + (state_size - 1) * 6 + 5) = 0; + if (V) printf(" n = %d x 2 côté = [%1.1f]\n", state_size + 1, 2.0f / state_size); *(line_ndx + 0) = 0; @@ -65,16 +91,27 @@ bool compute_space_2D(int state_size, for (int k = 0; k < state_size * 2; k++) *(line_ndx + k + 4) = k; if (I) printf("line_ndx (%d - state_size(0)) x (%d - state_size(1)) ", 0, 1); - for (int v = 0; v < state_size + 2; v++) { - if (I) printf("(%d-%d) ", *(line_ndx + v), *(line_ndx + v + 1)); - } - if (pref_mark_unit_space_zero) { // diagonales pour marquer la case zéro + for (int v = 0; v < state_size + 2; v++) + if (I) printf("(%d-%d) ", *(line_ndx + v), *(line_ndx + v + 1)); + + int dgap = 0; + + if (pref_mark_unit_space_first) { // diagonales to mark first space unit + dgap +=4; *(line_ndx + state_size * 2 + 6 + dgap + 0) = 0; *(line_ndx + state_size * 2 + 6 + dgap + 1) = 3; *(line_ndx + state_size * 2 + 6 + dgap + 2) = 1; *(line_ndx + state_size * 2 + 6 + dgap + 3) = 2; - } + } + + if (pref_mark_unit_space_last) { // diagonales to mark last space unit + dgap +=4; + *(line_ndx + state_size * 2 + 6 + dgap + 0) = (state_size - 2) * 2 + 0; + *(line_ndx + state_size * 2 + 6 + dgap + 1) = (state_size - 2) * 2 + 3; + *(line_ndx + state_size * 2 + 6 + dgap + 2) = (state_size - 2) * 2 + 1; + *(line_ndx + state_size * 2 + 6 + dgap + 3) = (state_size - 2) * 2 + 2; + } if (I) printf(" n = 4 + (%d x 2)\n", state_size + 2); diff --git a/src/graphics/space_3D.c b/src/graphics/space_3D.c index 10b1b33..62b6f86 100644 --- a/src/graphics/space_3D.c +++ b/src/graphics/space_3D.c @@ -25,13 +25,15 @@ #include #define V 1 -#define I 1 +#define I 0 #define EDGE 0.999999 bool compute_space_3D(int state_size, GLfloat *vertex_base, GLfloat *color_base, GLubyte *line_ndx, - bool pref_mark_unit_space_zero, int dgap){ + bool pref_mark_unit_space_first, + bool pref_mark_unit_space_last) +{ float x = 0; // for (int k = 0; k < state_size + 1; k++) <=> + 1 car @@ -62,36 +64,56 @@ bool compute_space_3D(int state_size, *(vertex_base + k * 12 + 10) = - 1.0f / state_size; *(vertex_base + k * 12 + 11) = 1.0f / state_size; - *(color_base + k * 12 + 0) = 1 - (k / state_size); - *(color_base + k * 12 + 1) = 0.2f; - *(color_base + k * 12 + 2) = (k / state_size); + *(color_base + k * 12 + 0) = 1; // 1 - (k / state_size); + *(color_base + k * 12 + 1) = 0; + *(color_base + k * 12 + 2) = 0; - *(color_base + k * 12 + 3) = 0.8f; - *(color_base + k * 12 + 4) = 0.8f; - *(color_base + k * 12 + 5) = 0.2f; + *(color_base + k * 12 + 3) = 0.2f; + *(color_base + k * 12 + 4) = 1; + *(color_base + k * 12 + 5) = 0; - *(color_base + k * 12 + 6) = 0.8f; - *(color_base + k * 12 + 7) = (k / state_size); - *(color_base + k * 12 + 8) = 0.2f; - - *(color_base + k * 12 + 9) = 1 - (k / state_size); - *(color_base + k * 12 + 10) = 0.2f; - *(color_base + k * 12 + 11) = 0.9f; - - // if (k == 0) for (int j = 0; j < 12; j++) *(color_base + j) = 0.2f; - -/* 0.8, 0.8, 0.8, // blanc */ -/* 0.8, 0.8, 0.2, // jaune */ -/* 0.8, 0.2, 0.2, // rouge */ -/* 0.2, 0.2, 0.2, // noir */ -/* 0.2, 0.2, 0.2, // gris */ -/* 0.2, 0.8, 0.8, // cyan */ -/* 0.2, 0.8, 0.2, // vert */ -/* 0.8, 0.2, 0.8, // magenta */ + *(color_base + k * 12 + 6) = 1; + *(color_base + k * 12 + 7) = 1; + *(color_base + k * 12 + 8) = 0; + *(color_base + k * 12 + 9) = 0; + *(color_base + k * 12 + 10) = 0; + *(color_base + k * 12 + 11) = 1; } - if (V) printf(" n = %d x 2 côté = [%1.1f]\n", state_size + 1, 2.0f / state_size); + *(color_base + 0) = 0; + *(color_base + 1) = 0; + *(color_base + 2) = 0; + + *(color_base + 3) = 1; + *(color_base + 4) = 1; + *(color_base + 5) = 1; + + *(color_base + 6) = 0; + *(color_base + 7) = 0; + *(color_base + 8) = 0; + + *(color_base + 9) = 1; + *(color_base + 10) = 1; + *(color_base + 11) = 1; + + *(color_base + (state_size - 1) * 12 + 0) = 1; + *(color_base + (state_size - 1) * 12 + 1) = 1; + *(color_base + (state_size - 1) * 12 + 2) = 1; + + *(color_base + (state_size - 1) * 12 + 3) = 0; + *(color_base + (state_size - 1) * 12 + 4) = 0; + *(color_base + (state_size - 1) * 12 + 5) = 0; + + *(color_base + (state_size - 1) * 12 + 6) = 0; + *(color_base + (state_size - 1) * 12 + 7) = 0; + *(color_base + (state_size - 1) * 12 + 8) = 0; + + *(color_base + (state_size - 1) * 12 + 9) = 1; + *(color_base + (state_size - 1) * 12 + 10) = 1; + *(color_base + (state_size - 1) * 12 + 11) = 1; + + if (V) printf(" n = %d x 2 côté = [%1.1f]\n", state_size + 1, 2.0f / state_size); *(line_ndx + 4) = 0; *(line_ndx + 5) = state_size * 4 - 4; // barre horizontale du bas arr @@ -131,7 +153,7 @@ bool compute_space_3D(int state_size, *(line_ndx + k + 7) = k / 2 - 2; // + 2; } -if (pref_mark_unit_space_zero) { +if (pref_mark_unit_space_first) { *(line_ndx + (2 + state_size) * 8 - 4) = 0 + 0; // diagonales pour marquer la case zéro *(line_ndx + (2 + state_size) * 8 - 3) = 0 + 1; @@ -140,13 +162,22 @@ if (pref_mark_unit_space_zero) { *(line_ndx + (2 + state_size) * 8 - 1) = 0 + 3; } +if (pref_mark_unit_space_last) { + + *(line_ndx + (2 + state_size) * 8 - 8) = (state_size - 1) * 4 + 0; // diagonales pour marquer la case finale + *(line_ndx + (2 + state_size) * 8 - 7) = (state_size - 1) * 4 + 1; + + *(line_ndx + (2 + state_size) * 8 - 6) = (state_size - 1) * 4 + 2; // diagonales pour marquer la case finale + *(line_ndx + (2 + state_size) * 8 - 5) = (state_size - 1) * 4 + 3; +} + if (I) printf("line_ndx "); for (int v = 0; v < state_size + 2; v++) { if (I) printf("(%d-%d) ", *(line_ndx + v), *(line_ndx + v + 1)); } - if (I) printf(" n = 4 + (%d x 2) dgap = %d\n", state_size + 2, dgap); - if (I) printf("pref_mark_unit_space_zero = %d ", pref_mark_unit_space_zero); + if (I) printf("pref_mark_unit_space_first = %d ", pref_mark_unit_space_first); + if (I) printf("pref_mark_unit_space_last = %d ", pref_mark_unit_space_last); return 1; diff --git a/src/shaders/shader.vert b/src/shaders/shader.vert index 39f3f08..7225b0a 100644 --- a/src/shaders/shader.vert +++ b/src/shaders/shader.vert @@ -12,5 +12,6 @@ out vec4 color; void main(void) { gl_Position = projection_matrix * view_matrix * model_matrix * vec4(in_position, 1); - color = vec4(1 * in_color.rgb, 0.2f); + color = vec4(1 * in_color.rgb, 1); + // color = vec4(1 * in_color.rgb, 0.2f); } \ No newline at end of file diff --git a/src/ui/events.c b/src/ui/events.c index 4c06ec4..2e1d469 100644 --- a/src/ui/events.c +++ b/src/ui/events.c @@ -25,7 +25,7 @@ #include #include "../../include/base.h" -#include "../../include/graphics_control.h" +#include "../../include/graphics.h" #include "../../include/ui.h"