From 75a3b7d9471b227aa1764d4cd0926944ed3a6889 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Wed, 3 Jul 2024 13:40:16 +0200 Subject: [PATCH] WIP: cleaning (widgets & graphics sub-dir creation II : 'graphics' > 'graph') --- include/{graphics.h => graph.h} | 118 +++++++++---------- include/{parsing.h => parse.h} | 0 src/callbacks.c | 10 +- src/{graphics => graph}/draw.c | 80 ++++++------- src/{graphics => graph}/graph_area.c | 52 ++++----- src/{graphics => graph}/graph_stack.c | 118 +++++++++---------- src/graph/grid.c | 162 ++++++++++++++++++++++++++ src/{graphics => graph}/init.c | 50 ++++---- src/{graphics => graph}/shader.frag | 0 src/{graphics => graph}/shader.vert | 0 src/graphics/grid.c | 162 -------------------------- src/{widgets => widget}/dialog.c | 0 src/{widgets => widget}/tree_lab.c | 0 src/{widgets => widget}/wdgt_lab_I | 0 src/{widgets => widget}/wdgt_lab_II.c | 0 src/{widgets => widget}/widgets.c | 0 16 files changed, 376 insertions(+), 376 deletions(-) rename include/{graphics.h => graph.h} (69%) rename include/{parsing.h => parse.h} (100%) rename src/{graphics => graph}/draw.c (68%) rename src/{graphics => graph}/graph_area.c (82%) rename src/{graphics => graph}/graph_stack.c (75%) create mode 100644 src/graph/grid.c rename src/{graphics => graph}/init.c (83%) rename src/{graphics => graph}/shader.frag (100%) rename src/{graphics => graph}/shader.vert (100%) delete mode 100644 src/graphics/grid.c rename src/{widgets => widget}/dialog.c (100%) rename src/{widgets => widget}/tree_lab.c (100%) rename src/{widgets => widget}/wdgt_lab_I (100%) rename src/{widgets => widget}/wdgt_lab_II.c (100%) rename src/{widgets => widget}/widgets.c (100%) diff --git a/include/graphics.h b/include/graph.h similarity index 69% rename from include/graphics.h rename to include/graph.h index b90cccc..e21285b 100644 --- a/include/graphics.h +++ b/include/graph.h @@ -44,7 +44,7 @@ * Structure describing a gl_area and its parameters, used to create a table * of Gem-graph client current gl_areas */ -struct graphic_stack_t { +struct graph_stack_t { int id; int mode; @@ -81,15 +81,15 @@ struct graphic_stack_t { /* * Dynamic array of ptrs to dynamically allocated gl_area_entry */ -extern struct graphic_stack_t *graphic_stack; +extern struct graph_stack_t *graph_stack; /* * Structure describing a gl_area and its parameters, used to create a table * of Gem-graph client current gl_areas */ -bool ui_render_stack(GtkWidget *container_widget); +bool graph_render_stack(GtkWidget *container_widget); -bool ui_setup_glarea(int target_mode, GtkWidget *target_widget); +bool graph_setup_glarea(int target_mode, GtkWidget *target_widget); /* * Initializes a gl_area @@ -98,7 +98,7 @@ bool ui_setup_glarea(int target_mode, GtkWidget *target_widget); * * @return true if initialized */ -int graphics_init(void *error_buffer); +int graph_init(void *error_buffer); /* * Draws the current buffer to a gl_area @@ -107,7 +107,7 @@ int graphics_init(void *error_buffer); * * @return void */ -void graphics_draw(const int stack_id); +void graph_draw(const int graph_stack_id); /* * Shutdowns a gl_area @@ -116,7 +116,7 @@ void graphics_draw(const int stack_id); * * @return true if success */ -bool graphics_shutdown(const int stack_id, void *error_buffer); +bool graph_shutdown(const int graph_stack_id, void *error_buffer); /* * Initializes the shaders of a gl_area and link them to a program @@ -125,18 +125,18 @@ bool graphics_shutdown(const int stack_id, void *error_buffer); * * @return true if initialized */ -bool graphics_init_shaders(const int stack_id); +bool graph_init_shaders(const int graph_stack_id); -bool ui_init_graphic_stack(void *container_widget, GError *error_buffer); -bool ui_shutdown_graphic_stack(void *container_widget, GError *error_buffer); -bool ui_update_axis_stack(GtkWidget *container_widget, int axis, int value); +bool graph_init_graph_stack(void *container_widget, GError *error_buffer); +bool graph_shutdown_graph_stack(void *container_widget, GError *error_buffer); +bool graph_update_axis_stack(GtkWidget *container_widget, int axis, int value); /* Initializes the buffer of a gl_area * Calls according to the user preferences * @param gl_area, ptr to the gl_area widget * @return void */ -void graphics_init_buffers(const int stack_id); +void graph_init_buffers(const int graph_stack_id); /* * Draws a vertex (x, y, z) @@ -146,7 +146,7 @@ void graphics_init_buffers(const int stack_id); * * @return void */ -void graphics_draw_vertex (const int stack_id, +void graph_draw_vertex (const int graph_stack_id, GLfloat x, GLfloat y, GLfloat z); @@ -159,7 +159,7 @@ void graphics_draw_vertex (const int stack_id, * * @return void */ -void graphics_draw_color (const int stack_id, GLfloat r, GLfloat g, GLfloat b); +void graph_draw_color (const int graph_stack_id, GLfloat r, GLfloat g, GLfloat b); /* * Writes values to describe a line from a to b into the line buffer @@ -168,7 +168,7 @@ void graphics_draw_color (const int stack_id, GLfloat r, GLfloat g, GLfloat b); * * @return void */ -void graphics_draw_line (const int stack_id, GLuint a, GLuint b); +void graph_draw_line (const int graph_stack_id, GLuint a, GLuint b); /* * Writes values to describe an (a,b,c) plan (triangle) into the plan buffer @@ -177,7 +177,7 @@ void graphics_draw_line (const int stack_id, GLuint a, GLuint b); * * @return void */ -void graphics_draw_plan (const int stack_id, GLuint a, GLuint b, GLuint c); +void graph_draw_plan (const int graph_stack_id, GLuint a, GLuint b, GLuint c); /* * Created and compile a shader @@ -187,7 +187,7 @@ void graphics_draw_plan (const int stack_id, GLuint a, GLuint b, GLuint c); * * @return shader id */ -static inline GLuint create_shader(const int stack_id, int type, const char *src) +static inline GLuint graph_create_shader(const int graph_stack_id, int type, const char *src) { GLuint shader; int status; @@ -221,47 +221,47 @@ static inline GLuint create_shader(const int stack_id, int type, const char *src return shader; } -static inline void print_stack(int stack_id) +static inline void graph_print_stack(int graph_stack_id) { static int n = 0; printf("\n[n=%d]***************", n); printf("id = %d\tmode = %d\n", - graphic_stack[stack_id].id, - graphic_stack[stack_id].mode); + graph_stack[graph_stack_id].id, + graph_stack[graph_stack_id].mode); printf("rotation_angles = "); for (int i = 0; i < N_AXIS; i++) { - printf("%f\t", graphic_stack[stack_id].rotation_angles[i]); // Rotation angles on each axis + printf("%f\t", graph_stack[graph_stack_id].rotation_angles[i]); // Rotation angles on each axis } printf("\n"); - printf("vao = %d\n", graphic_stack[stack_id].vao); - printf("position_buffer = %d\n", graphic_stack[stack_id].position_buffer); - printf("color_buffer = %d\n", graphic_stack[stack_id].color_buffer); - printf("program = %d\n", graphic_stack[stack_id].program); - printf("m = %d\n", graphic_stack[stack_id].m); - printf("v = %d\n", graphic_stack[stack_id].v); - printf("p = %d\n", graphic_stack[stack_id].p); + printf("vao = %d\n", graph_stack[graph_stack_id].vao); + printf("position_buffer = %d\n", graph_stack[graph_stack_id].position_buffer); + printf("color_buffer = %d\n", graph_stack[graph_stack_id].color_buffer); + printf("program = %d\n", graph_stack[graph_stack_id].program); + printf("m = %d\n", graph_stack[graph_stack_id].m); + printf("v = %d\n", graph_stack[graph_stack_id].v); + printf("p = %d\n", graph_stack[graph_stack_id].p); - printf("arrows_ptr = %p\n", graphic_stack[stack_id].arrows_ptr); - printf("arrows_nb = %ld\n", graphic_stack[stack_id].arrows_nb); + printf("arrows_ptr = %p\n", graph_stack[graph_stack_id].arrows_ptr); + printf("arrows_nb = %ld\n", graph_stack[graph_stack_id].arrows_nb); - printf("buffer_vertex_origin = %p\n", graphic_stack[stack_id].buffer_vertex_origin); - printf("buffer_colors_origin = %p\n", graphic_stack[stack_id].buffer_colors_origin); - printf("buffer_lines_origin = %p\n", graphic_stack[stack_id].buffer_lines_origin); - printf("buffer_plans_origin = %p\n", graphic_stack[stack_id].buffer_plans_origin); + printf("buffer_vertex_origin = %p\n", graph_stack[graph_stack_id].buffer_vertex_origin); + printf("buffer_colors_origin = %p\n", graph_stack[graph_stack_id].buffer_colors_origin); + printf("buffer_lines_origin = %p\n", graph_stack[graph_stack_id].buffer_lines_origin); + printf("buffer_plans_origin = %p\n", graph_stack[graph_stack_id].buffer_plans_origin); - printf("buffer_vertex_size = %ld\n", graphic_stack[stack_id].buffer_vertex_size); - printf("buffer_colors_size = %ld\n", graphic_stack[stack_id].buffer_colors_size); - printf("buffer_lines_size = %ld\n", graphic_stack[stack_id].buffer_lines_size); - printf("buffer_plans_size = %ld\n", graphic_stack[stack_id].buffer_plans_size); + printf("buffer_vertex_size = %ld\n", graph_stack[graph_stack_id].buffer_vertex_size); + printf("buffer_colors_size = %ld\n", graph_stack[graph_stack_id].buffer_colors_size); + printf("buffer_lines_size = %ld\n", graph_stack[graph_stack_id].buffer_lines_size); + printf("buffer_plans_size = %ld\n", graph_stack[graph_stack_id].buffer_plans_size); - printf("buffer_vertex_0_arrow = %ld\n", graphic_stack[stack_id].buffer_vertex_0_arrow); - printf("buffer_colors_0_arrow = %ld\n", graphic_stack[stack_id].buffer_colors_0_arrow); - printf("buffer_lines_0_arrow = %ld\n", graphic_stack[stack_id].buffer_lines_0_arrow); - printf("buffer_plans_0_arrow = %ld\n", graphic_stack[stack_id].buffer_plans_0_arrow); + printf("buffer_vertex_0_arrow = %ld\n", graph_stack[graph_stack_id].buffer_vertex_0_arrow); + printf("buffer_colors_0_arrow = %ld\n", graph_stack[graph_stack_id].buffer_colors_0_arrow); + printf("buffer_lines_0_arrow = %ld\n", graph_stack[graph_stack_id].buffer_lines_0_arrow); + printf("buffer_plans_0_arrow = %ld\n", graph_stack[graph_stack_id].buffer_plans_0_arrow); printf("********************\n"); n++; @@ -275,7 +275,7 @@ static inline void print_stack(int stack_id) * * @return true if initialized */ -int graphics_init(void *error_buffer); +int graph_init(void *error_buffer); /* * Draws the current buffer to a gl_area @@ -284,7 +284,7 @@ int graphics_init(void *error_buffer); * * @return void */ -//void graphics_draw(const int stack_id); +//void graph_draw(const int graph_stack_id); /* * Shutdowns a gl_area @@ -293,7 +293,7 @@ int graphics_init(void *error_buffer); * * @return true if success */ -bool graphics_shutdown(const int stack_id, void *error_buffer); +bool graph_shutdown(const int graph_stack_id, void *error_buffer); /* * Initializes the shaders of a gl_area and link them to a program @@ -302,14 +302,14 @@ bool graphics_shutdown(const int stack_id, void *error_buffer); * * @return true if initialized */ -bool graphics_init_shaders(const int stack_id); +bool graph_init_shaders(const int graph_stack_id); /* Initializes the buffer of a gl_area * Calls according to the user preferences * @param gl_area, ptr to the gl_area widget * @return void */ -void graphics_init_buffers(const int stack_id); +void graph_init_buffers(const int graph_stack_id); /* * Draws a vertex (x, y, z) @@ -319,7 +319,7 @@ void graphics_init_buffers(const int stack_id); * * @return void */ -void graphics_draw_vertex (const int stack_id, +void graph_draw_vertex (const int graph_stack_id, GLfloat x, GLfloat y, GLfloat z); @@ -332,7 +332,7 @@ void graphics_draw_vertex (const int stack_id, * * @return void */ -void graphics_draw_color (const int stack_id, GLfloat r, GLfloat g, GLfloat b); +void graph_draw_color (const int graph_stack_id, GLfloat r, GLfloat g, GLfloat b); /* * Writes values to describe a line from a to b into the line buffer @@ -341,7 +341,7 @@ void graphics_draw_color (const int stack_id, GLfloat r, GLfloat g, GLfloat b); * * @return void */ -void graphics_draw_line (const int stack_id, GLuint a, GLuint b); +void graph_draw_line (const int graph_stack_id, GLuint a, GLuint b); /* * Writes values to describe an (a,b,c) plan (triangle) into the plan buffer @@ -350,11 +350,11 @@ void graphics_draw_line (const int stack_id, GLuint a, GLuint b); * * @return void */ -void graphics_draw_plan (const int stack_id, GLuint a, GLuint b, GLuint c); +void graph_draw_plan (const int graph_stack_id, GLuint a, GLuint b, GLuint c); -void graphics_model_setup (const int stack_id); +void graph_model_setup (const int graph_stack_id); -int draw_one_arrow_vertex (const int stack_id, +int graph_draw_one_arrow_vertex (const int graph_stack_id, int space_X, int space_Y, int space_Z, @@ -364,7 +364,7 @@ int draw_one_arrow_vertex (const int stack_id, int y, int z); -int draw_one_arrow_line(const int stack_id, +int graph_draw_one_arrow_line(const int graph_stack_id, int offset_vertex); /* @@ -374,13 +374,13 @@ int draw_one_arrow_line(const int stack_id, * * @return void */ -int draw_space_ridges_vertex (const int stack_id, +int graph_draw_space_ridges_vertex (const int graph_stack_id, long offset_vertex, long x, long y, long z); -int draw_space_ridges_lines (const int stack_id); +int graph_draw_space_ridges_lines (const int graph_stack_id); /* * Writes grid lines on space faces @@ -389,18 +389,18 @@ int draw_space_ridges_lines (const int stack_id); * * @return void */ -long draw_grids_on_space_faces_vertex (const int stack_id, +long graph_draw_grids_on_space_faces_vertex (const int graph_stack_id, long x, long y, long z); -long draw_grids_on_space_faces_lines (const int stack_id, +long graph_draw_grids_on_space_faces_lines (const int graph_stack_id, long offset_vertex, long x, long y, long z); -int set_arrow (int stack_id, +int graph_set_arrow (int graph_stack_id, int arrows_nb, int space_X, int space_Y, diff --git a/include/parsing.h b/include/parse.h similarity index 100% rename from include/parsing.h rename to include/parse.h diff --git a/src/callbacks.c b/src/callbacks.c index 5a42ab8..6a8d8c3 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -28,7 +28,7 @@ #include "../include/callbacks.h" #include "../include/widgets.h" -#include "../include/graphics.h" +#include "../include/graph.h" /******************************************************************************/ @@ -135,7 +135,7 @@ gboolean on_glarea_render(GtkGLArea *area, return false; } - if (graphics_render_stack(gtk_widget_get_parent(GTK_WIDGET(area))) == false) { + if (graph_render_stack(gtk_widget_get_parent(GTK_WIDGET(area))) == false) { on_auto_notification("Failed to render corresponding graphic stack !"); return false; } @@ -159,7 +159,7 @@ void on_glarea_realize(GtkWidget *widget) } // Link graphical stack to widget - if (graphics_init_graphic_stack(gtk_widget_get_parent(widget), + if (graph_init_graph_stack(gtk_widget_get_parent(widget), internal_error) == false) { on_auto_notification( "Failed to link the graphic stack to widgets !"); @@ -184,7 +184,7 @@ void on_glarea_unrealize(GtkWidget *widget) } // Destroy graphic stack - if (graphics_shutdown_graphic_stack(gtk_widget_get_parent(widget), + if (graph_shutdown_graph_stack(gtk_widget_get_parent(widget), internal_error) == false) { on_auto_notification( "Failed to shutdown the graphic stack !"); @@ -206,7 +206,7 @@ void on_axis_value_change(GtkAdjustment *adjustment, gpointer data) g_assert(axis >= 0 && axis < N_AXIS); /* Update the rotation angle */ - graphics_update_axis_stack(container_widget, + graph_update_axis_stack(container_widget, axis, gtk_adjustment_get_value(adjustment)); diff --git a/src/graphics/draw.c b/src/graph/draw.c similarity index 68% rename from src/graphics/draw.c rename to src/graph/draw.c index f9e3589..6fb32dc 100644 --- a/src/graphics/draw.c +++ b/src/graph/draw.c @@ -29,7 +29,7 @@ #include #include "../../include/base.h" -#include "../../include/graphics.h" +#include "../../include/graph.h" /* * Writes values to describe a vertex at (x,y,z) intoq the vertex buffer @@ -38,7 +38,7 @@ * * @return void */ -void graphics_draw_vertex (const int stack_id, +void graph_draw_vertex (const int stack_id, GLfloat x, GLfloat y, GLfloat z) @@ -47,22 +47,22 @@ void graphics_draw_vertex (const int stack_id, //g_printerr("stack_id is %d\n", stack_id); //g_printerr("graphic_stack is at %p\n", graphic_stack); //g_printerr("graphic_stack[stack_id] is at %p\n", graphic_stack + stack_id); - volatile struct graphic_stack_t *stack = &graphic_stack[stack_id]; + volatile struct graph_stack_t *graph_stack = &graph_stack[stack_id]; //g_printerr("Currently stack->buffer_vertex_origin @ %p\n", stack->buffer_vertex_origin); //assert (stack->buffer_vertex_origin); - stack->buffer_vertex_origin = - g_realloc (stack->buffer_vertex_origin, - (stack->buffer_vertex_size + 3) * sizeof(GLfloat)); + graph_stack->buffer_vertex_origin = + g_realloc (graph_stack->buffer_vertex_origin, + (graph_stack->buffer_vertex_size + 3) * sizeof(GLfloat)); //print_stack(stack_id); - stack->buffer_vertex_origin[stack->buffer_vertex_size + 0] = x; - stack->buffer_vertex_origin[stack->buffer_vertex_size + 1] = y; - stack->buffer_vertex_origin[stack->buffer_vertex_size + 2] = z; + graph_stack->buffer_vertex_origin[graph_stack->buffer_vertex_size + 0] = x; + graph_stack->buffer_vertex_origin[graph_stack->buffer_vertex_size + 1] = y; + graph_stack->buffer_vertex_origin[graph_stack->buffer_vertex_size + 2] = z; - stack->buffer_vertex_size += 3; + graph_stack->buffer_vertex_size += 3; } /* @@ -72,23 +72,23 @@ void graphics_draw_vertex (const int stack_id, * * @return void */ -void graphics_draw_color (const int stack_id, +void graph_draw_color (const int stack_id, GLfloat r, GLfloat g, GLfloat b) { - struct graphic_stack_t *stack = &graphic_stack[stack_id]; + struct graph_stack_t *graph_stack = &graph_stack[stack_id]; - stack->buffer_colors_origin = g_realloc (stack->buffer_colors_origin, - (stack->buffer_colors_size + 3) * sizeof(GLfloat)); + graph_stack->buffer_colors_origin = g_realloc (graph_stack->buffer_colors_origin, + (graph_stack->buffer_colors_size + 3) * sizeof(GLfloat)); - assert (stack->buffer_colors_origin); + assert (graph_stack->buffer_colors_origin); - stack->buffer_colors_origin[stack->buffer_colors_size + 0] = r; - stack->buffer_colors_origin[stack->buffer_colors_size + 1] = g; - stack->buffer_colors_origin[stack->buffer_colors_size + 2] = b; + graph_stack->buffer_colors_origin[graph_stack->buffer_colors_size + 0] = r; + graph_stack->buffer_colors_origin[graph_stack->buffer_colors_size + 1] = g; + graph_stack->buffer_colors_origin[graph_stack->buffer_colors_size + 2] = b; - stack->buffer_colors_size += 3; + graph_stack->buffer_colors_size += 3; } /* @@ -98,21 +98,21 @@ void graphics_draw_color (const int stack_id, * * @return void */ -void graphics_draw_line (const int stack_id, +void graph_draw_line (const int stack_id, GLuint a, GLuint b) { - struct graphic_stack_t *stack = &graphic_stack[stack_id]; + struct graph_stack_t *stack = &graph_stack[stack_id]; - stack->buffer_lines_origin = g_realloc (stack->buffer_lines_origin, - (stack->buffer_lines_size + 2) * sizeof(GLuint)); + graph_stack->buffer_lines_origin = g_realloc (graph_stack->buffer_lines_origin, + (graph_stack->buffer_lines_size + 2) * sizeof(GLuint)); - assert (stack->buffer_lines_origin); + assert (graph_stack->buffer_lines_origin); - stack->buffer_lines_origin[stack->buffer_lines_size + 0] = a; - stack->buffer_lines_origin[stack->buffer_lines_size + 1] = b; + graph_stack->buffer_lines_origin[graph_stack->buffer_lines_size + 0] = a; + graph_stack->buffer_lines_origin[graph_stack->buffer_lines_size + 1] = b; - stack->buffer_lines_size += 2; + graph_stack->buffer_lines_size += 2; } /* @@ -122,23 +122,23 @@ void graphics_draw_line (const int stack_id, * * @return void */ -void graphics_draw_plan (const int stack_id, +void graph_draw_plan (const int stack_id, GLuint a, GLuint b, GLuint c) { - struct graphic_stack_t *stack = &graphic_stack[stack_id]; + struct graph_stack_t *stack = &graph_stack[stack_id]; - stack->buffer_plans_origin = g_realloc (stack->buffer_plans_origin, - (stack->buffer_plans_size + 3) * sizeof(GLuint)); + graph_stack->buffer_plans_origin = g_realloc (graph_stack->buffer_plans_origin, + (graph_stack->buffer_plans_size + 3) * sizeof(GLuint)); assert (stack->buffer_plans_origin); - stack->buffer_plans_origin[stack->buffer_plans_size + 0] = a; - stack->buffer_plans_origin[stack->buffer_plans_size + 1] = b; - stack->buffer_plans_origin[stack->buffer_plans_size + 2] = c; + graph_stack->buffer_plans_origin[graph_stack->buffer_plans_size + 0] = a; + graph_stack->buffer_plans_origin[graph_stack->buffer_plans_size + 1] = b; + graph_stack->buffer_plans_origin[graph_stack->buffer_plans_size + 2] = c; - stack->buffer_plans_size += 3; + graph_stack->buffer_plans_size += 3; } /* @@ -148,13 +148,13 @@ void graphics_draw_plan (const int stack_id, * * @return void */ -void graphics_draw(const int stack_id) +void graph_draw(const int stack_id) { - struct graphic_stack_t *stack = &graphic_stack[stack_id]; + struct graph_stack_t *stack = &graph_stack[stack_id]; - g_printerr("[debug] graphics_draw() started\n"); + g_printerr("[debug] graph_draw() started\n"); - print_stack(stack_id); + graph_print_stack(stack_id); GLint cur_viewport[4]; glGetIntegerv(GL_VIEWPORT, cur_viewport); @@ -204,5 +204,5 @@ void graphics_draw(const int stack_id) glUseProgram(0); glFlush(); - g_printerr("[debug] graphics_draw() ended\n"); + g_printerr("[debug] graph_draw() ended\n"); } diff --git a/src/graphics/graph_area.c b/src/graph/graph_area.c similarity index 82% rename from src/graphics/graph_area.c rename to src/graph/graph_area.c index e7b3b3b..a41f8f3 100644 --- a/src/graphics/graph_area.c +++ b/src/graph/graph_area.c @@ -25,7 +25,7 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include "../../include/graphics.h" +#include "../../include/graph.h" #include "../../include/callbacks.h" struct stack_index_t { @@ -62,7 +62,7 @@ int set_arrow (int stack_id, // 2024-06-27 DEBUG ! * * @returns stack_id */ -long graphics_get_graphic_stack(void *container_widget) +long graph_get_graph_stack(void *container_widget) { // look for stack_index entry for (int i = 0; i < stack_index_size; i++) { @@ -80,7 +80,7 @@ long graphics_get_graphic_stack(void *container_widget) * * @returns stack_id */ -long graphics_is_graphic_stack_ready(void *container_widget) +long graph_is_graph_stack_ready(void *container_widget) { // look for stack_index entry for (int i = 0; i < stack_index_size; i++) { @@ -98,20 +98,20 @@ long graphics_is_graphic_stack_ready(void *container_widget) * * @returns bool, true if success */ -bool graphics_init_graphic_stack(void *container_widget, GError *error_buffer) +bool graph_init_graph_stack(void *container_widget, GError *error_buffer) { - g_printerr("[debug] graphics_init_graphic_stack()\n"); + g_printerr("[debug] graph_init_graph_stack()\n"); - g_printerr("[debug] graphics_init_graphic_stack() : target is %p\n", container_widget); + g_printerr("[debug] graph_init_graph_stack() : target is %p\n", container_widget); // look for stack_index entry for (int i = 0; i < stack_index_size; i++) { - g_printerr("[debug] graphics_init_graphic_stack() : i is %d\n", i); - g_printerr("[debug] graphics_init_graphic_stack() : target would be %p\n", + g_printerr("[debug] graph_init_graph_stack() : i is %d\n", i); + g_printerr("[debug] graph_init_graph_stack() : target would be %p\n", stack_index[i].container_widget); if (stack_index[i].container_widget == (void *)container_widget) { - stack_index[i].stack_id = graphics_init(&error_buffer); - g_printerr("[debug] graphics_init_graphic_stack() : stack_id is %ld\n", + stack_index[i].stack_id = graph_init(&error_buffer); + g_printerr("[debug] graph_init_graph_stack() : stack_id is %ld\n", stack_index[i].stack_id); if (stack_index[i].stack_id >= 0) return true; @@ -129,12 +129,12 @@ bool graphics_init_graphic_stack(void *container_widget, GError *error_buffer) * * @returns bool, true if success */ -bool graphics_shutdown_graphic_stack(void *container_widget, GError *error_buffer) +bool graph_shutdown_graph_stack(void *container_widget, GError *error_buffer) { // look for stack_index entry for (int i = 0; i < stack_index_size; i++) { if (stack_index[i].container_widget == (void *)container_widget) { - if (graphics_shutdown(stack_index[i].stack_id, + if (graph_shutdown(stack_index[i].stack_id, &error_buffer) == false) { return false; } @@ -146,7 +146,7 @@ bool graphics_shutdown_graphic_stack(void *container_widget, GError *error_buffe } -void graphics_clean_stack_index(void) +void graph_clean_stack_index(void) { // look for stack_index entry for (int i = 0; i < stack_index_size; i++) { @@ -162,19 +162,19 @@ void graphics_clean_stack_index(void) * * @returns bool, true if success */ -bool graphics_render_stack(GtkWidget *container_widget) +bool graph_render_stack(GtkWidget *container_widget) { // look for stack_index entry for (int i = 0; i < stack_index_size; i++) { if (stack_index[i].container_widget == (void *)container_widget) { - graphics_draw (stack_index[i].stack_id); + graph_draw (stack_index[i].stack_id); return true; } } return false; } -//void graphics_draw(const int stack_id) {printf("graph_area.c > void graphics_draw(const int stack_id) (161)\n");} +//void graph_draw(const int stack_id) {printf("graph_area.c > void graph_draw(const int stack_id) (161)\n");} /* * Look for stack entry and triggers OpenGL for drawing @@ -183,12 +183,12 @@ bool graphics_render_stack(GtkWidget *container_widget) * * @returns bool, true if success */ -bool graphics_update_axis_stack(GtkWidget *container_widget, int axis, int value) +bool graph_update_axis_stack(GtkWidget *container_widget, int axis, int value) { // look for stack_index entry for (int i = 0; i < stack_index_size; i++) { if (stack_index[i].container_widget == (void *)container_widget) { - graphic_stack[stack_index[i].stack_id].rotation_angles[axis] = value; + graph_stack[stack_index[i].stack_id].rotation_angles[axis] = value; gtk_widget_queue_draw((GtkWidget*)(stack_index[i].gl_area)); return true; } @@ -203,11 +203,11 @@ bool graphics_update_axis_stack(GtkWidget *container_widget, int axis, int value * * @returns bool, true if success */ -void graphics_shutdown_all_graphic_stacks(void) +void graph_shutdown_all_graph_stacks(void) { // look for stack_index entry for (int i = 0; i < stack_index_size; i++) { - graphics_shutdown(stack_index[i].stack_id, NULL); + graph_shutdown(stack_index[i].stack_id, NULL); } return; } @@ -263,20 +263,20 @@ GtkWidget *create_axis_slider(int axis) /* * Creates GLArea and indexes it * - * @params target_mode, meaning which graphics_stack we're on + * @params target_mode, meaning which graph_stack we're on * target_widget, meaning the box that will host the GLArea * * @returns bool, true if success */ -bool graphics_setup_glarea(int target_mode, GtkWidget *target_widget) +bool graph_setup_glarea(int target_mode, GtkWidget *target_widget) { GtkWidget *gl_area; - g_printerr("[debug] graphics_setup_glarea()\n"); + g_printerr("[debug] graph_setup_glarea()\n"); assert(target_widget); - g_printerr("[debug] graphics_setup_glarea() : target is %p\n", target_widget); + g_printerr("[debug] graph_setup_glarea() : target is %p\n", target_widget); if (stack_index == NULL) { stack_index = g_malloc(sizeof(struct stack_index_t)); @@ -314,9 +314,9 @@ bool graphics_setup_glarea(int target_mode, GtkWidget *target_widget) stack_index[stack_index_size-1].gl_area = (void*)gl_area; - g_printerr("[debug] graphics_setup_glarea() : set target to %p\n", target_widget); + g_printerr("[debug] graph_setup_glarea() : set target to %p\n", target_widget); - g_printerr("[debug] graphics_setup_glarea() : stack_index (@0x%p) had %ld elements\n", + g_printerr("[debug] graph_setup_glarea() : stack_index (@0x%p) had %ld elements\n", stack_index, stack_index_size); diff --git a/src/graphics/graph_stack.c b/src/graph/graph_stack.c similarity index 75% rename from src/graphics/graph_stack.c rename to src/graph/graph_stack.c index b404fb2..0c21365 100644 --- a/src/graphics/graph_stack.c +++ b/src/graph/graph_stack.c @@ -26,13 +26,13 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include "../../include/graphics.h" -#include "../../include/parsing.h" +#include "../../include/graph.h" +#include "../../include/parse.h" #define TEST 0 -struct graphic_stack_t *graphic_stack = NULL; -size_t graphic_stack_size = 0; +struct graph_stack_t *graph_stack = NULL; +size_t graph_stack_size = 0; int *free_stack_slot = NULL; size_t free_stack_slot_size = 0; @@ -50,7 +50,7 @@ size_t free_stack_slot_size = 0; * @return void */ -static void graphics_debug_callback(GLenum source, GLenum type, GLuint id, +static void graph_debug_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *msg, const void *data) { @@ -105,17 +105,17 @@ static void graphics_debug_callback(GLenum source, GLenum type, GLuint id, * * @return id if initialized */ -int graphics_init(void *error_buffer) +int graph_init(void *error_buffer) { int cur_id = 0; - struct graphic_stack_t *stack; + struct graph_stack_t *graph_stack; - g_printerr("[debug] graphics_init()\n"); + g_printerr("[debug] graph_init()\n"); - if (graphic_stack == NULL) { - graphic_stack = g_malloc0(sizeof(struct graphic_stack_t)); - graphic_stack_size = 1; - g_printerr("[debug] graphics_init(): init graphic_stack @ %p\n", graphic_stack); + if (graph_stack == NULL) { + graph_stack = g_malloc0(sizeof(struct graph_stack_t)); + graph_stack_size = 1; + g_printerr("[debug] graph_init(): init graph_stack @ %p\n", graph_stack); } else { // Check if there are free slots if (free_stack_slot_size) { @@ -126,33 +126,33 @@ int graphics_init(void *error_buffer) free_stack_slot_size-- * sizeof(int)); } else { - cur_id = graphic_stack_size; - graphic_stack = g_realloc(graphic_stack, - ++graphic_stack_size * - sizeof(struct graphic_stack_t)); + cur_id = graph_stack_size; + graph_stack = g_realloc(graph_stack, + ++graph_stack_size * + sizeof(struct graph_stack_t)); } } - memset(&graphic_stack[cur_id], 0, sizeof(struct graphic_stack_t)); + memset(&graph_stack[cur_id], 0, sizeof(struct graph_stack_t)); - g_printerr("[debug] graphics_init() : graphic_stack (@0x%p) has %ld elements\n", - graphic_stack, - graphic_stack_size); + g_printerr("[debug] graph_init() : graph_stack (@0x%p) has %ld elements\n", + graph_stack, + graph_stack_size); - stack = &graphic_stack[cur_id]; - stack->id = cur_id; + graph_stack = &graph_stack[cur_id]; + graph_stack->id = cur_id; glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); glEnable(GL_MULTISAMPLE); - if (!graphics_init_shaders(cur_id)) return -1; + if (!graph_init_shaders(cur_id)) return -1; - print_stack(cur_id); + graph_print_stack(cur_id); - graphics_init_buffers(cur_id); + graph_init_buffers(cur_id); - glDebugMessageCallback(graphics_debug_callback, NULL); + glDebugMessageCallback(graph_debug_callback, NULL); //print_stack(cur_id); @@ -166,37 +166,37 @@ int graphics_init(void *error_buffer) * * @return true if success */ -bool graphics_shutdown(const int id, void *error_buffer) +bool graph_shutdown(const int id, void *error_buffer) { - struct graphic_stack_t *stack; + struct graph_stack_t *graph_stack; - if (id >= graphic_stack_size || - graphic_stack_size == 0 || - graphic_stack == NULL) + if (id >= graph_stack_size || + graph_stack_size == 0 || + graph_stack == NULL) return false; - stack = &graphic_stack[id]; + graph_stack = &graph_stack[id]; //XXX - free(stack->arrows_ptr); - stack->arrows_ptr = NULL; - stack->arrows_nb = 0; + free(graph_stack->arrows_ptr); + graph_stack->arrows_ptr = NULL; + graph_stack->arrows_nb = 0; - glDeleteBuffers(1, &stack->position_buffer); - glDeleteBuffers(1, &stack->color_buffer); - glDeleteProgram(stack->program); + glDeleteBuffers(1, &graph_stack->position_buffer); + glDeleteBuffers(1, &graph_stack->color_buffer); + glDeleteProgram(graph_stack->program); - g_free(stack->buffer_vertex_origin); - g_free(stack->buffer_colors_origin); - g_free(stack->buffer_lines_origin); - g_free(stack->buffer_plans_origin); + g_free(graph_stack->buffer_vertex_origin); + g_free(graph_stack->buffer_colors_origin); + g_free(graph_stack->buffer_lines_origin); + g_free(graph_stack->buffer_plans_origin); - if (graphic_stack_size == 1) { - free(graphic_stack); - graphic_stack = NULL; - graphic_stack_size = 0; + if (graph_stack_size == 1) { + free(graph_stack); + graph_stack = NULL; + graph_stack_size = 0; } else { - memset(&graphic_stack[id], 0, sizeof(struct graphic_stack_t)); + memset(&graph_stack[id], 0, sizeof(struct graph_stack_t)); free_stack_slot = g_realloc(free_stack_slot, ++free_stack_slot_size * sizeof(int)); @@ -225,7 +225,7 @@ bool graphics_shutdown(const int id, void *error_buffer) * Attention, les vertex centraux de chaque unité d'espace (cube) * peuvent être redondants (max 6) */ -void graphics_model_setup (const int stack_id) +void graph_model_setup (const int stack_id) { /*------------------------------------------------------------------------*/ @@ -233,7 +233,7 @@ void graphics_model_setup (const int stack_id) /*------------------------------------------------------------------------*/ - struct graphic_stack_t *stack = &graphic_stack[stack_id]; + struct graph_stack_t *graph_stack = &graph_stack[stack_id]; char dimension; long space_X; long space_Y; @@ -274,7 +274,7 @@ void graphics_model_setup (const int stack_id) g_print("[GRAPH DEBUG] z = %ld\n", space_Z); density_max = space_X * space_Y * space_Z; - stack->arrows_nb = 0; + graph_stack->arrows_nb = 0; multiplicity = model_get_multiplicity(); g_print("[GRAPH DEBUG] site_multiplicity = %d, density_max = %d\n", multiplicity, density_max); @@ -285,14 +285,14 @@ void graphics_model_setup (const int stack_id) /*------------------------------------------------------------------------*/ - draw_space_ridges_vertex (stack_id, stack->buffer_vertex_size, space_X, space_Y, space_Z); - draw_space_ridges_lines (stack_id); - draw_grids_on_space_faces_vertex (stack_id, space_X, space_Y, space_Z); - draw_grids_on_space_faces_lines (stack_id, stack->buffer_lines_size, space_X, space_Y, space_Z); + graph_draw_space_ridges_vertex (stack_id, graph_stack->buffer_vertex_size, space_X, space_Y, space_Z); + graph_draw_space_ridges_lines (stack_id); + graph_draw_grids_on_space_faces_vertex (stack_id, space_X, space_Y, space_Z); + graph_draw_grids_on_space_faces_lines (stack_id, graph_stack->buffer_lines_size, space_X, space_Y, space_Z); - stack->buffer_vertex_0_arrow = stack->buffer_vertex_size; - stack->buffer_colors_0_arrow = stack->buffer_colors_size; - stack->buffer_lines_0_arrow = stack->buffer_lines_size; + graph_stack->buffer_vertex_0_arrow = graph_stack->buffer_vertex_size; + graph_stack->buffer_colors_0_arrow = graph_stack->buffer_colors_size; + graph_stack->buffer_lines_0_arrow = graph_stack->buffer_lines_size; /*------------------------------------------------------------------------*/ @@ -313,10 +313,10 @@ void graphics_model_setup (const int stack_id) while (model_get_next_arrow(&arrow, (char *)&state_id, dimension)) { g_print("[GRAPH DEBUG] cur arrow has x = %d\n", arrow.x); - stack->arrows_nb = set_arrow (stack_id, stack->arrows_nb, space_X, space_Y, space_Z, arrow.load, arrow.site, arrow.x, arrow.y, arrow.z); + graph_stack->arrows_nb = set_arrow (stack_id, graph_stack->arrows_nb, space_X, space_Y, space_Z, arrow.load, arrow.site, arrow.x, arrow.y, arrow.z); } - if (stack->arrows_nb != announced_arrows_nb) + if (graph_stack->arrows_nb != announced_arrows_nb) g_printerr("ARGH : not all arrows have been parsed !\n"); } diff --git a/src/graph/grid.c b/src/graph/grid.c new file mode 100644 index 0000000..b2f290d --- /dev/null +++ b/src/graph/grid.c @@ -0,0 +1,162 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * +* * +* Gem-graph client * +* * +* Drawing empty space * +* * +* Copyright © 2021 Libre en Communs * +* Copyright © 2023 Adrien Bourmault * +* Copyright © 2024 Jean Sirmai * +* * +* This file is part of Gem-graph. * +* * +* This program is free software: you can redistribute it and/or modify it * +* under the terms of the GNU Affero General Public License * +* as publishedby the Free Software Foundation, * +* either version 3 of the License, or (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * +* See the GNU Affero General Public License for more details. * +* * +* You should have received a copy of the GNU Affero General Public License * +* along with this program. If not, see . * +* * +* * * * * * * * * * * * * * * * * * * * * * * * * * */ + + +#include "../../include/graph.h" + +int graph_draw_space_ridges_vertex (const int stack_id, + long offset_vertex, + long x, + long y, + long z) +{ + GLfloat max = fmax(x, y); max = fmax(max, z); + + graph_draw_vertex (stack_id, offset_vertex - x / max, offset_vertex - y / max, - z / max); + + graph_draw_vertex (stack_id, offset_vertex + x / max, offset_vertex - y / max, - z / max); + graph_draw_vertex (stack_id, offset_vertex - x / max, offset_vertex + y / max, - z / max); + graph_draw_vertex (stack_id, offset_vertex - x / max, offset_vertex - y / max, + z / max); + + graph_draw_vertex (stack_id, offset_vertex + x / max, offset_vertex + y / max, - z / max); + graph_draw_vertex (stack_id, offset_vertex + x / max, offset_vertex - y / max, + z / max); + graph_draw_vertex (stack_id, offset_vertex - x / max, offset_vertex + y / max, + z / max); + + graph_draw_vertex (stack_id, offset_vertex + x / max, + y / max, + z / max); + + graph_draw_color (stack_id, 0.8f, 0.6f, 0.5f); + graph_draw_color (stack_id, 0.8f, 0.6f, 0.5f); + graph_draw_color (stack_id, 0.8f, 0.6f, 0.5f); + graph_draw_color (stack_id, 0.8f, 0.6f, 0.5f); + graph_draw_color (stack_id, 0.8f, 0.6f, 0.5f); + graph_draw_color (stack_id, 0.8f, 0.6f, 0.5f); + graph_draw_color (stack_id, 0.8f, 0.6f, 0.5f); + graph_draw_color (stack_id, 0.8f, 0.6f, 0.5f); + + return 8; +} + +int graph_draw_space_ridges_lines (const int stack_id) +{ + graph_draw_line (stack_id, 0, 1); graph_draw_line (stack_id, 7, 4); + graph_draw_line (stack_id, 0, 2); graph_draw_line (stack_id, 7, 5); + graph_draw_line (stack_id, 0, 3); graph_draw_line (stack_id, 7, 6); + + graph_draw_line (stack_id, 1, 4); graph_draw_line (stack_id, 2, 4); + graph_draw_line (stack_id, 1, 5); graph_draw_line (stack_id, 3, 5); + graph_draw_line (stack_id, 2, 6); graph_draw_line (stack_id, 3, 6); + + return 12; +} + +long graph_draw_grids_on_space_faces_vertex (const int stack_id, + long x, + long y, + long z) +{ + float i, max = fmax(x, y); max = fmax(max, z); + + for (i = 1; i < x; i++) { + + graph_draw_vertex (stack_id, (2 * i / x - 1) * x / max, - y / max, - z / max); + graph_draw_vertex (stack_id, (2 * i / x - 1) * x / max, - y / max, z / max); + graph_draw_vertex (stack_id, (2 * i / x - 1) * x / max, y / max, z / max); + graph_draw_vertex (stack_id, (2 * i / x - 1) * x / max, y / max, - z / max); + + graph_draw_color (stack_id, 0.55f, 0.55f, 0.55f); + graph_draw_color (stack_id, 0.55f, 0.55f, 0.55f); + graph_draw_color (stack_id, 0.55f, 0.55f, 0.55f); + graph_draw_color (stack_id, 0.55f, 0.55f, 0.55f); + } + + /* offset_vertex += (x - 1) * 4; */ /* offset_colors += (x - 1) * 4; */ + + for (i = 1; i < y; i++) { + + graph_draw_vertex (stack_id, - x / max, (2 * i / y - 1) * y / max, - z / max); + graph_draw_vertex (stack_id, - x / max, (2 * i / y - 1) * y / max, z / max); + graph_draw_vertex (stack_id, x / max, (2 * i / y - 1) * y / max, z / max); + graph_draw_vertex (stack_id, x / max, (2 * i / y - 1) * y / max, - z / max); + + graph_draw_color (stack_id, 0.55f, 0.55f, 0.55f); + graph_draw_color (stack_id, 0.55f, 0.55f, 0.55f); + graph_draw_color (stack_id, 0.55f, 0.55f, 0.55f); + graph_draw_color (stack_id, 0.55f, 0.55f, 0.55f); + } + + /* offset_vertex += (y - 1) * 4; */ /* offset_colors += (y - 1) * 4; */ + + for (i = 1; i < z; i++) { + + graph_draw_vertex (stack_id, - x / max, - y / max, (2 * i / z - 1) * z / max); + graph_draw_vertex (stack_id, - x / max, y / max, (2 * i / z - 1) * z / max); + graph_draw_vertex (stack_id, x / max, y / max, (2 * i / z - 1) * z / max); + graph_draw_vertex (stack_id, x / max, - y / max, (2 * i / z - 1) * z / max); + + graph_draw_color (stack_id, 0.55f, 0.55f, 0.55f); + graph_draw_color (stack_id, 0.55f, 0.55f, 0.55f); + graph_draw_color (stack_id, 0.55f, 0.55f, 0.55f); + graph_draw_color (stack_id, 0.55f, 0.55f, 0.55f); + } + + return (x + y + z - 3) * 3; +} + + +long graph_draw_grids_on_space_faces_lines (const int stack_id, + long offset_vertex, + long x, + long y, + long z) +{ + offset_vertex = offset_vertex / 3; + + for (int i = 0; i < x - 1; i ++) { + + graph_draw_line (stack_id, offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2); + graph_draw_line (stack_id, offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3); + } + + offset_vertex += (x - 1) * 4; + + for (int i = 0; i < y - 1; i ++) { + + graph_draw_line (stack_id, offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3); + graph_draw_line (stack_id, offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0); + } + + offset_vertex += (y - 1) * 4; + + for (int i = 0; i < z - 1; i ++) { + + graph_draw_line (stack_id, offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1); + graph_draw_line (stack_id, offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0); + } + + return (x + y + z - 3) * 4; +} + diff --git a/src/graphics/init.c b/src/graph/init.c similarity index 83% rename from src/graphics/init.c rename to src/graph/init.c index 233ddf8..526f735 100644 --- a/src/graphics/init.c +++ b/src/graph/init.c @@ -28,28 +28,28 @@ /* -------------------------------------------------------------------------- */ -#include "../../include/graphics.h" +#include "../../include/graph.h" /* Initializes the buffer of a gl_area * Calls according to the user preferences * @param gl_area, ptr to the gl_area widget * @return void */ -void graphics_init_buffers(const int stack_id) +void graph_init_buffers(const int stack_id) { - struct graphic_stack_t *stack = &graphic_stack[stack_id]; + struct graph_stack_t *graph_stack = &graph_stack[stack_id]; //XXX - graphics_model_setup(stack_id); + graph_model_setup(stack_id); GLuint vao, vertex_buffer, color_buffer; glGenBuffers(1, &vertex_buffer); glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); glBufferData(GL_ARRAY_BUFFER, - stack->buffer_vertex_size * - sizeof(stack->buffer_vertex_origin[0]), - stack->buffer_vertex_origin, + graph_stack->buffer_vertex_size * + sizeof(graph_stack->buffer_vertex_origin[0]), + graph_stack->buffer_vertex_origin, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -57,9 +57,9 @@ void graphics_init_buffers(const int stack_id) // colors glGenBuffers(1, &color_buffer); glBindBuffer(GL_ARRAY_BUFFER, color_buffer); - glBufferData(GL_ARRAY_BUFFER, stack->buffer_colors_size * - sizeof(stack->buffer_colors_origin[0]), - stack->buffer_colors_origin, + glBufferData(GL_ARRAY_BUFFER, graph_stack->buffer_colors_size * + sizeof(graph_stack->buffer_colors_origin[0]), + graph_stack->buffer_colors_origin, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -67,9 +67,9 @@ void graphics_init_buffers(const int stack_id) glGenVertexArrays(1, &vao); glBindVertexArray(vao); - stack->vao = vao; - stack->position_buffer = vertex_buffer; - stack->color_buffer = color_buffer; + graph_stack->vao = vao; + graph_stack->position_buffer = vertex_buffer; + graph_stack->color_buffer = color_buffer; } /* @@ -79,9 +79,9 @@ void graphics_init_buffers(const int stack_id) * * @return true if initialized */ -bool graphics_init_shaders(const int stack_id) +bool graph_init_shaders(const int stack_id) { - struct graphic_stack_t *stack = &graphic_stack[stack_id]; + struct graph_stack_t *graph_stack = &graph_stack[stack_id]; char *vertex_shader; char *fragment_shader; int status; @@ -95,10 +95,10 @@ bool graphics_init_shaders(const int stack_id) vertex_shader = read_file(VERTEX_SHADER_FILE); if (vertex_shader == NULL) return false; - vertex = create_shader(stack_id, GL_VERTEX_SHADER, vertex_shader); + vertex = graph_create_shader(stack_id, GL_VERTEX_SHADER, vertex_shader); if(vertex == 0) { - stack->program = 0; + graph_stack->program = 0; g_free(vertex_shader); return false; } @@ -107,11 +107,11 @@ bool graphics_init_shaders(const int stack_id) fragment_shader = read_file(FRAG_SHADER_FILE); if (fragment_shader == NULL) return false; - fragment = create_shader(stack_id, GL_FRAGMENT_SHADER, fragment_shader); + fragment = graph_create_shader(stack_id, GL_FRAGMENT_SHADER, fragment_shader); if(fragment == 0) { glDeleteShader(vertex); - stack->program = 0; + graph_stack->program = 0; g_free(vertex_shader); g_free(fragment_shader); return false; @@ -120,7 +120,7 @@ bool graphics_init_shaders(const int stack_id) // Link shaders to program program = glCreateProgram(); printf("\n------------------------------------------------------------------------------------------\n"); - printf("[debug] graphics_init_shaders() : program = %d, vertex = %d, fragment = %d\n\ + printf("[debug] graph_init_shaders() : program = %d, vertex = %d, fragment = %d\n\ exec > ** (myprogram:-----): WARNING ** : --:--:--:---: Linking failure: (address)\n", program, vertex, fragment); @@ -134,7 +134,7 @@ bool graphics_init_shaders(const int stack_id) glAttachShader(program, vertex); glAttachShader(program, fragment); - printf("Failed to link the graphic stack to widgets ! <> see init.c graphics_init_shaders()\n"); + printf("Failed to link the graphic stack to widgets ! <> see init.c graph_init_shaders()\n"); printf("the error in not : vertex shader lacks `main' but : failed to link... (comment line 140)\n"); // https://registry.khronos.org/OpenGL-Refpages/gl4/html/glLinkProgram.xhtml // glLinkProgram(program); // Linking failure: (address) @@ -179,10 +179,10 @@ bool graphics_init_shaders(const int stack_id) glDeleteShader(vertex); glDeleteShader(fragment); - stack->program = program; - stack->m = m; - stack->v = v; - stack->p = p; + graph_stack->program = program; + graph_stack->m = m; + graph_stack->v = v; + graph_stack->p = p; g_free(vertex_shader); g_free(fragment_shader); diff --git a/src/graphics/shader.frag b/src/graph/shader.frag similarity index 100% rename from src/graphics/shader.frag rename to src/graph/shader.frag diff --git a/src/graphics/shader.vert b/src/graph/shader.vert similarity index 100% rename from src/graphics/shader.vert rename to src/graph/shader.vert diff --git a/src/graphics/grid.c b/src/graphics/grid.c deleted file mode 100644 index 8549668..0000000 --- a/src/graphics/grid.c +++ /dev/null @@ -1,162 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * -* * -* Gem-graph client * -* * -* Drawing empty space * -* * -* Copyright © 2021 Libre en Communs * -* Copyright © 2023 Adrien Bourmault * -* Copyright © 2024 Jean Sirmai * -* * -* This file is part of Gem-graph. * -* * -* This program is free software: you can redistribute it and/or modify it * -* under the terms of the GNU Affero General Public License * -* as publishedby the Free Software Foundation, * -* either version 3 of the License, or (at your option) any later version. * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * -* See the GNU Affero General Public License for more details. * -* * -* You should have received a copy of the GNU Affero General Public License * -* along with this program. If not, see . * -* * -* * * * * * * * * * * * * * * * * * * * * * * * * * */ - - -#include "../../include/graphics.h" - -int draw_space_ridges_vertex (const int stack_id, - long offset_vertex, - long x, - long y, - long z) -{ - GLfloat max = fmax(x, y); max = fmax(max, z); - - graphics_draw_vertex (stack_id, offset_vertex - x / max, offset_vertex - y / max, - z / max); - - graphics_draw_vertex (stack_id, offset_vertex + x / max, offset_vertex - y / max, - z / max); - graphics_draw_vertex (stack_id, offset_vertex - x / max, offset_vertex + y / max, - z / max); - graphics_draw_vertex (stack_id, offset_vertex - x / max, offset_vertex - y / max, + z / max); - - graphics_draw_vertex (stack_id, offset_vertex + x / max, offset_vertex + y / max, - z / max); - graphics_draw_vertex (stack_id, offset_vertex + x / max, offset_vertex - y / max, + z / max); - graphics_draw_vertex (stack_id, offset_vertex - x / max, offset_vertex + y / max, + z / max); - - graphics_draw_vertex (stack_id, offset_vertex + x / max, + y / max, + z / max); - - graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f); - graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f); - graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f); - graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f); - graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f); - graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f); - graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f); - graphics_draw_color (stack_id, 0.8f, 0.6f, 0.5f); - - return 8; -} - -int draw_space_ridges_lines (const int stack_id) -{ - graphics_draw_line (stack_id, 0, 1); graphics_draw_line (stack_id, 7, 4); - graphics_draw_line (stack_id, 0, 2); graphics_draw_line (stack_id, 7, 5); - graphics_draw_line (stack_id, 0, 3); graphics_draw_line (stack_id, 7, 6); - - graphics_draw_line (stack_id, 1, 4); graphics_draw_line (stack_id, 2, 4); - graphics_draw_line (stack_id, 1, 5); graphics_draw_line (stack_id, 3, 5); - graphics_draw_line (stack_id, 2, 6); graphics_draw_line (stack_id, 3, 6); - - return 12; -} - -long draw_grids_on_space_faces_vertex (const int stack_id, - long x, - long y, - long z) -{ - float i, max = fmax(x, y); max = fmax(max, z); - - for (i = 1; i < x; i++) { - - graphics_draw_vertex (stack_id, (2 * i / x - 1) * x / max, - y / max, - z / max); - graphics_draw_vertex (stack_id, (2 * i / x - 1) * x / max, - y / max, z / max); - graphics_draw_vertex (stack_id, (2 * i / x - 1) * x / max, y / max, z / max); - graphics_draw_vertex (stack_id, (2 * i / x - 1) * x / max, y / max, - z / max); - - graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f); - graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f); - graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f); - graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f); - } - - /* offset_vertex += (x - 1) * 4; */ /* offset_colors += (x - 1) * 4; */ - - for (i = 1; i < y; i++) { - - graphics_draw_vertex (stack_id, - x / max, (2 * i / y - 1) * y / max, - z / max); - graphics_draw_vertex (stack_id, - x / max, (2 * i / y - 1) * y / max, z / max); - graphics_draw_vertex (stack_id, x / max, (2 * i / y - 1) * y / max, z / max); - graphics_draw_vertex (stack_id, x / max, (2 * i / y - 1) * y / max, - z / max); - - graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f); - graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f); - graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f); - graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f); - } - - /* offset_vertex += (y - 1) * 4; */ /* offset_colors += (y - 1) * 4; */ - - for (i = 1; i < z; i++) { - - graphics_draw_vertex (stack_id, - x / max, - y / max, (2 * i / z - 1) * z / max); - graphics_draw_vertex (stack_id, - x / max, y / max, (2 * i / z - 1) * z / max); - graphics_draw_vertex (stack_id, x / max, y / max, (2 * i / z - 1) * z / max); - graphics_draw_vertex (stack_id, x / max, - y / max, (2 * i / z - 1) * z / max); - - graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f); - graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f); - graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f); - graphics_draw_color (stack_id, 0.55f, 0.55f, 0.55f); - } - - return (x + y + z - 3) * 3; -} - - -long draw_grids_on_space_faces_lines (const int stack_id, - long offset_vertex, - long x, - long y, - long z) -{ - offset_vertex = offset_vertex / 3; - - for (int i = 0; i < x - 1; i ++) { - - graphics_draw_line (stack_id, offset_vertex + i * 4 + 1, offset_vertex + i * 4 + 2); - graphics_draw_line (stack_id, offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3); - } - - offset_vertex += (x - 1) * 4; - - for (int i = 0; i < y - 1; i ++) { - - graphics_draw_line (stack_id, offset_vertex + i * 4 + 2, offset_vertex + i * 4 + 3); - graphics_draw_line (stack_id, offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0); - } - - offset_vertex += (y - 1) * 4; - - for (int i = 0; i < z - 1; i ++) { - - graphics_draw_line (stack_id, offset_vertex + i * 4 + 0, offset_vertex + i * 4 + 1); - graphics_draw_line (stack_id, offset_vertex + i * 4 + 3, offset_vertex + i * 4 + 0); - } - - return (x + y + z - 3) * 4; -} - diff --git a/src/widgets/dialog.c b/src/widget/dialog.c similarity index 100% rename from src/widgets/dialog.c rename to src/widget/dialog.c diff --git a/src/widgets/tree_lab.c b/src/widget/tree_lab.c similarity index 100% rename from src/widgets/tree_lab.c rename to src/widget/tree_lab.c diff --git a/src/widgets/wdgt_lab_I b/src/widget/wdgt_lab_I similarity index 100% rename from src/widgets/wdgt_lab_I rename to src/widget/wdgt_lab_I diff --git a/src/widgets/wdgt_lab_II.c b/src/widget/wdgt_lab_II.c similarity index 100% rename from src/widgets/wdgt_lab_II.c rename to src/widget/wdgt_lab_II.c diff --git a/src/widgets/widgets.c b/src/widget/widgets.c similarity index 100% rename from src/widgets/widgets.c rename to src/widget/widgets.c