diff --git a/Capture d’écran du 2023-05-25 22-32-00.png b/Capture d’écran du 2023-05-25 22-32-00.png new file mode 100644 index 0000000..2ad74d0 Binary files /dev/null and b/Capture d’écran du 2023-05-25 22-32-00.png differ diff --git a/Capture d’écran du 2023-05-27 20-51-23.png b/Capture d’écran du 2023-05-27 20-51-23.png new file mode 100644 index 0000000..7e206c3 Binary files /dev/null and b/Capture d’écran du 2023-05-27 20-51-23.png differ diff --git a/Capture d’écran du 2023-05-27 23-27-49.png b/Capture d’écran du 2023-05-27 23-27-49.png new file mode 100644 index 0000000..a2af3db Binary files /dev/null and b/Capture d’écran du 2023-05-27 23-27-49.png differ diff --git a/Capture d’écran du 2023-06-11 22-48-35.png b/Capture d’écran du 2023-06-11 22-48-35.png new file mode 100644 index 0000000..de96316 Binary files /dev/null and b/Capture d’écran du 2023-06-11 22-48-35.png differ diff --git a/Capture d’écran du 2023-06-13 23-21-09.png b/Capture d’écran du 2023-06-13 23-21-09.png new file mode 100644 index 0000000..b551f95 Binary files /dev/null and b/Capture d’écran du 2023-06-13 23-21-09.png differ diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index c29c87d..d0e4822 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -38,17 +38,18 @@ #include "../../include/base.h" #include "../../include/ui.h" #include "../../include/graphics.h" -#include "../../include/graphics_cube.h" #define VERTEX_SHADER_FILE "src/shaders/shader.vert" #define FRAG_SHADER_FILE "src/shaders/shader.frag" #define K 0 GLfloat *vertex_base = NULL; +GLfloat *color_base = NULL; GLubyte *indices = NULL; int dim = 0; int state_size = 0; int vertex_nb = 0; +int colors_nb = 0; int segments_nb = 0; int arrows_nb = 0; @@ -314,10 +315,11 @@ bool graphics_shutdown(const void *gl_area) entry = NULL; gl_area_array = g_realloc(gl_area_array, - (gl_area_size()) + (gl_area_size()) * sizeof(struct gl_area_entry *)); g_free(vertex_base); + g_free(color_base); g_free(indices); return true; } @@ -566,6 +568,18 @@ static bool compute_arrow_2D(struct gl_area_entry *entry, int state_size, int vg if (A) printf("x = %d site = %d center = %f tip = %f base = %f\n",\ x, site, center, tip, base); // vgap=%d igap=%d + /* *(color_base + vgap + 0) = 0.2f; // cyan */ + /* *(color_base + vgap + 1) = 0.8f; */ + /* *(color_base + vgap + 2) = 0.8f; */ + + /* *(color_base + vgap + 3) = 0.8f; // magenta */ + /* *(color_base + vgap + 4) = 0.2f; */ + /* *(color_base + vgap + 5) = 0.8f; */ + + /* *(color_base + vgap + 6) = 0.8f; // jaune */ + /* *(color_base + vgap + 7) = 0.8f; */ + /* *(color_base + vgap + 8) = 0.2f; */ + assert(igap < entry->indices_nb); assert(igap + 5 < entry->indices_nb); @@ -722,6 +736,8 @@ static bool compute_space_3D(struct gl_area_entry *entry, int state_size){ assert(k * 12 < vertex_nb); assert(k * 12 + 11 < vertex_nb); + assert(k * 12 < colors_nb); + assert(k * 12 + 11 < colors_nb); *(vertex_base + k * 12 + 0) = - x; *(vertex_base + k * 12 + 1) = 1.0f / state_size; @@ -738,6 +754,32 @@ static bool compute_space_3D(struct gl_area_entry *entry, int state_size){ *(vertex_base + k * 12 + 9) = - x; *(vertex_base + k * 12 + 10) = - 1.0f / state_size; *(vertex_base + k * 12 + 11) = 1.0f / state_size; + + *(color_base + k * 12 + 0) = 0.8f; // rouge + *(color_base + k * 12 + 1) = 0.2f; + *(color_base + k * 12 + 2) = 0.2f; + + *(color_base + k * 12 + 3) = 0.8f; // jaune + *(color_base + k * 12 + 4) = 0.8f; + *(color_base + k * 12 + 5) = 0.2f; + + *(color_base + k * 12 + 6) = 0.2f; // vert + *(color_base + k * 12 + 7) = 0.8f; + *(color_base + k * 12 + 8) = 0.2f; + + *(color_base + k * 12 + 9) = 0.8f; // magenta + *(color_base + k * 12 + 10) = 0.2f; + *(color_base + k * 12 + 11) = 0.8f; + +/* 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 */ + } if (V) printf(" n = %d x 2 côté = [%1.1f]\n", state_size + 1, 2.0f / state_size); @@ -802,46 +844,48 @@ void graphics_init_buffers(const void *gl_area) { struct gl_area_entry *entry; GLuint vao, vertex_buffer, color_buffer; - int vgap = 0, igap = 0; + int vgap = 0, igap = 0, cgap = 0; entry = find_entry_from_ptr(gl_area); //{1, 1, 0, 1, 2, 1, 1, 1, 10, 1, 2, 11, 1, 1, 20, 1, 2, 21}; dim = 1; state_size = 13; // 2 < state_size < 32 - arrows_nb = 6; + arrows_nb = 4; vertex_nb = (state_size + 1) * 6 + arrows_nb * 9; vertex_nb = (state_size + 1) * 12 + arrows_nb * 15; + colors_nb = (state_size + 1) * 12 + arrows_nb * 0; // TODO segments_nb = (2 + state_size) + (arrows_nb * 3); segments_nb = (4 + state_size * 4) + (arrows_nb * 8) + 2; // + 2; pour les 2 diagonales entry->indices_nb = segments_nb * 2; - printf("Initialization of buffers with %u indices and %u vertices & state_size = %d\n", - entry->indices_nb, vertex_nb, state_size); + printf("Initialization of buffers with %u indices, %u vertices and %u colors & state_size = %d\n", + entry->indices_nb, vertex_nb, colors_nb, state_size); //XXX g_malloc vertex_base = g_malloc0(vertex_nb * sizeof(GLfloat) * 2); + color_base = g_malloc0(colors_nb * sizeof(GLfloat) * 2); indices = g_malloc0(segments_nb * 2 * sizeof(GLubyte) * 2); -// compute_space_2D(entry, state_size); vgap += (6 * state_size); igap += state_size * 2 + 4; +// compute_space_2D(entry, state_size); vgap += (6 * state_size); igap += state_size * 2 + 4; cgap += (6 * state_size); - compute_space_3D(entry, state_size); vgap += (12 * state_size); igap += state_size * 8 + 8; + compute_space_3D(entry, state_size); vgap += (12 * state_size); igap += state_size * 8 + 8; cgap += (12 * state_size); - /* compute_arrow_2D(entry, state_size, vgap, igap, 1, 1, 2, 0, 0); vgap += 9; igap += 6; ++arrows_nb; */ - /* compute_arrow_2D(entry, state_size, vgap, igap, 1, 1, 0, 0, 0); vgap += 9; igap += 6; */ - /* compute_arrow_2D(entry, state_size, vgap, igap, 1, 0, 3, 0, 0); vgap += 9; igap += 6; */ - /* compute_arrow_2D(entry, state_size, vgap, igap, 1, 1, 3, 0, 0); vgap += 9; igap += 6; */ - /* compute_arrow_2D(entry, state_size, vgap, igap, 1, 0, state_size - 2, 0, 0); vgap += 9; igap += 6; */ - /* compute_arrow_2D(entry, state_size, vgap, igap, 1, 1, state_size - 2, 0, 0); vgap += 9; igap += 6; */ + /* compute_arrow_2D(entry, state_size, vgap, igap, 1, 1, 2, 0, 0); vgap += 9; igap += 6; cgap += 15; ++arrows_nb; */ + /* compute_arrow_2D(entry, state_size, vgap, igap, 1, 1, 0, 0, 0); vgap += 9; igap += 6; cgap += 15; ++arrows_nb; */ + /* compute_arrow_2D(entry, state_size, vgap, igap, 1, 0, 3, 0, 0); vgap += 9; igap += 6; cgap += 15; ++arrows_nb; */ + /* compute_arrow_2D(entry, state_size, vgap, igap, 1, 1, 3, 0, 0); vgap += 9; igap += 6; cgap += 15; ++arrows_nb; */ + /* compute_arrow_2D(entry, state_size, vgap, igap, 1, 0, state_size - 2, 0, 0); vgap += 9; igap += 6; cgap += 15; ++arrows_nb; */ + /* compute_arrow_2D(entry, state_size, vgap, igap, 1, 1, state_size - 2, 0, 0); vgap += 9; igap += 6; cgap += 15; ++arrows_nb; */ - compute_arrow_3D(entry, state_size, vgap, igap, 1, 1, 2, 0, 0); vgap += 15; igap += 16; ++arrows_nb; - compute_arrow_3D(entry, state_size, vgap, igap, 1, 1, 0, 0, 0); vgap += 15; igap += 16; - compute_arrow_3D(entry, state_size, vgap, igap, 1, 0, 3, 0, 0); vgap += 15; igap += 16; - compute_arrow_3D(entry, state_size, vgap, igap, 1, 1, 3, 0, 0); vgap += 15; igap += 16; - compute_arrow_3D(entry, state_size, vgap, igap, 1, 0, state_size - 2, 0, 0); vgap += 15; igap += 16; - compute_arrow_3D(entry, state_size, vgap, igap, 1, 1, state_size - 2, 0, 0); vgap += 15; igap += 16; + compute_arrow_3D(entry, state_size, vgap, igap, 1, 0, 0, 0, 0); vgap += 15; igap += 16; cgap += 15; ++arrows_nb; + compute_arrow_3D(entry, state_size, vgap, igap, 1, 1, 2, 0, 0); vgap += 15; igap += 16; cgap += 15; ++arrows_nb; + compute_arrow_3D(entry, state_size, vgap, igap, 1, 0, 3, 0, 0); vgap += 15; igap += 16; cgap += 15; ++arrows_nb; + //compute_arrow_3D(entry, state_size, vgap, igap, 1, 1, 3, 0, 0); vgap += 15; igap += 16; cgap += 15; ++arrows_nb; + //compute_arrow_3D(entry, state_size, vgap, igap, 1, 0, state_size - 2, 0, 0); vgap += 15; igap += 16; cgap += 15; ++arrows_nb; + compute_arrow_3D(entry, state_size, vgap, igap, 1, 1, state_size - 2, 0, 0); vgap += 15; igap += 16; cgap += 15; ++arrows_nb; // We only use one VAO, so we always keep it bound glGenVertexArrays(1, &vao); @@ -853,15 +897,15 @@ void graphics_init_buffers(const void *gl_area) glBindBuffer(GL_ARRAY_BUFFER, 0); // colors - /* glGenBuffers(1, &color_buffer); */ - /* glBindBuffer(GL_ARRAY_BUFFER, color_buffer); */ - /* glBufferData(GL_ARRAY_BUFFER, sizeof(color_base), color_base, GL_STATIC_DRAW); */ - /* glBindBuffer(GL_ARRAY_BUFFER, 0); */ + glGenBuffers(1, &color_buffer); + glBindBuffer(GL_ARRAY_BUFFER, color_buffer); + glBufferData(GL_ARRAY_BUFFER, sizeof(color_base[0]), color_base, GL_STATIC_DRAW); // TODO check : color_base[0] or color_base ? + glBindBuffer(GL_ARRAY_BUFFER, 0); if(entry != NULL) { entry->vao = vao; entry->position_buffer = vertex_buffer; - //entry->color_buffer = color_buffer; + entry->color_buffer = color_buffer; } } @@ -898,7 +942,7 @@ void graphics_draw(const void *gl_area) compute_i(m); compute_i(v); - glClearColor(0, 0, 0, 0); + glClearColor(0.1f, 0.1f, 0.1f, 0.15f); // couleur du 'fond' glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Use our shaders */ @@ -915,9 +959,9 @@ void graphics_draw(const void *gl_area) glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0,(void*)0); // couleurs - /* glEnableVertexAttribArray(1); */ - /* glBindBuffer(GL_ARRAY_BUFFER, entry->color_buffer); */ - /* glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0,(void*)0); */ + glEnableVertexAttribArray(1); + glBindBuffer(GL_ARRAY_BUFFER, entry->color_buffer); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0,(void*)0); glEnable(GL_DEPTH_TEST);