From b9cb86c17cfb58723169670d2b137cf80ccd0180 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Thu, 6 Jun 2024 10:22:15 +0200 Subject: [PATCH] WIP: cleaning, simplifying, organizing #include graph_stack : shaders readed in init.c --- (notes) | 46 +++++++++++----------------------------------- init.c.todo | 4 ++-- shader.frag | 9 +++++++++ shader.vert | 20 ++++++++++++++++++++ 4 files changed, 42 insertions(+), 37 deletions(-) create mode 100644 shader.frag create mode 100644 shader.vert diff --git a/(notes) b/(notes) index b0fad33..cc3c095 100644 --- a/(notes) +++ b/(notes) @@ -1,50 +1,26 @@ jean@Project:~/01/Gtk4/Getting_Started_with_GTK [env] $ grep -r "////...////" -contain.c: (136) gtk_box_append (middle_box, GTK_WIDGET (get_GLArea())); +contain.c: (136) gtk_box_append (middle_box, GTK_WIDGET (get_GLArea())); graph_area.h: (177) static inline GLuint create_shader(const int stack_id, int type, const char *src) {...} -graph_area.c: (153) graphics_draw (stack_index[i].stack_id); +graph_area.c: (153) graphics_draw (stack_index[i].stack_id); graph_area.c: (233) g_signal_connect (adj, "value-changed", G_CALLBACK(on_axis_value_change), (gpointer) label); graph_area.c: (289) g_signal_connect(GTK_GL_AREA(gl_area), "render", G_CALLBACK(on_glarea_render), NULL); graph_area.c: g_signal_connect(gl_area, "realize", G_CALLBACK(on_glarea_realize), NULL); graph_area.c: g_signal_connect(gl_area, "unrealize", G_CALLBACK(on_glarea_unrealize), NULL); -init.c.todo: (98) vertex = create_shader(stack_id, GL_VERTEX_SHADER, vertex_shader); -init.c.todo: (110) fragment = create_shader(stack_id, GL_FRAGMENT_SHADER, fragment_shader); +init.c.todo: (98) vertex = create_shader(stack_id, GL_VERTEX_SHADER, vertex_shader); +init.c.todo: (110) fragment = create_shader(stack_id, GL_FRAGMENT_SHADER, fragment_shader); +graph_stack.c: (149) if (!graphics_init_shaders(cur_id)) return -1; +graph_stack.c: (153) graphics_init_buffers(cur_id); +graph_stack.c: (288) draw_space_ridges_vertex (stack_id, stack->buffer_vertex_size, space_X, space_Y, space_Z); +graph_stack.c: draw_space_ridges_lines (stack_id); +graph_stack.c: draw_grids_on_space_faces_vertex (stack_id, space_X, space_Y, space_Z); +graph_stack.c: draw_grids_on_space_faces_lines (stack_id, stack->buffer_lines_size, space_X, space_Y, space_Z); +graph_stack.c: (316) 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.c:////...//// glEnable(GL_DEBUG_OUTPUT); -graph_stack.c:////...//// glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); -graph_stack.c:////...//// glEnable(GL_MULTISAMPLE); -graph_stack.c:////...//// if (!graphics_init_shaders(cur_id)) return -1; -graph_stack.c:////...//// graphics_init_buffers(cur_id); -graph_stack.c:////...//// glDebugMessageCallback(graphics_debug_callback, NULL); -graph_stack.c:////...//// dimension = model_get_dim(); -graph_stack.c:////...//// space_Z = model_get_dim_value("z"); -graph_stack.c:////...//// space_Y = model_get_dim_value("y"); -graph_stack.c:////...//// space_X = model_get_dim_value("x"); -graph_stack.c:////...//// multiplicity = model_get_multiplicity(); -graph_stack.c:////...//// g_print("[GRAPH DEBUG] site_multiplicity = %ld\n", multiplicity); -graph_stack.c:////...//// draw_space_ridges_vertex (stack_id, stack->buffer_vertex_size, space_X, space_Y, space_Z); -graph_stack.c:////...//// draw_space_ridges_lines (stack_id); -graph_stack.c:////...//// draw_grids_on_space_faces_vertex (stack_id, space_X, space_Y, space_Z); -graph_stack.c:////...//// draw_grids_on_space_faces_lines (stack_id, stack->buffer_lines_size, space_X, space_Y, space_Z); -graph_stack.c:////...//// assert(model_get_next_state(&state_id)); -graph_stack.c:////...//// announced_arrows_nb = model_get_state_arrows_count(state_id); -graph_stack.c:////...//// g_print("[GRAPH DEBUG] announced_arrows_nb is = %ld\n", announced_arrows_nb); -graph_stack.c:////...//// while (model_get_next_arrow(&arrow, &state_id, dimension)) { -graph_stack.c:////...//// g_print("[GRAPH DEBUG] cur arrow has x = %d\n", arrow.x); -graph_stack.c:////...//// stack->arrows_nb = -graph_stack.c:////...//// set_arrow (stack_id, stack->arrows_nb, space_X, space_Y, space_Z, -graph_stack.c:////...//// arrow.load, // load -graph_stack.c:////...//// arrow.site, // site -graph_stack.c:////...//// arrow.x, // x -graph_stack.c:////...//// arrow.y, // y -graph_stack.c:////...//// arrow.z); // z -graph_stack.c:////...//// } -graph_stack.c:////...//// if (stack->arrows_nb != announced_arrows_nb) -graph_stack.c:////...//// g_printerr("ARGH : all the arrows have not been parsed !\n"); -------------------------------------------------------------------------------- https://docs.gtk.org/gtk4/visual_index.html widgets gallery https://forge.a-lec.org/gem-graph/gem-graph-client/src/branch/devel/Makefile diff --git a/init.c.todo b/init.c.todo index 375b5ca..7789ec0 100644 --- a/init.c.todo +++ b/init.c.todo @@ -95,7 +95,7 @@ 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 = create_shader(stack_id, GL_VERTEX_SHADER, vertex_shader); if(vertex == 0) { stack->program = 0; @@ -107,7 +107,7 @@ 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 = create_shader(stack_id, GL_FRAGMENT_SHADER, fragment_shader); if(fragment == 0) { glDeleteShader(vertex); diff --git a/shader.frag b/shader.frag new file mode 100644 index 0000000..fb8a76c --- /dev/null +++ b/shader.frag @@ -0,0 +1,9 @@ +#version 330 core + +in vec4 color; +out vec4 out_frag_color; + +void main(void) +{ + out_frag_color = color; +} \ No newline at end of file diff --git a/shader.vert b/shader.vert new file mode 100644 index 0000000..09e953c --- /dev/null +++ b/shader.vert @@ -0,0 +1,20 @@ +#version 330 core + +uniform mat4 projection_matrix; +uniform mat4 model_matrix; +uniform mat4 view_matrix; + +layout(location=0) in vec3 in_position; +layout(location=1) in vec3 in_color; + +out vec4 color; + +void main(void) +{ + float zoom = 1.1f, chrominance = 1, luminance = 1; + gl_Position = + projection_matrix * view_matrix * model_matrix * vec4(in_position, zoom); + color = vec4 (chrominance * in_color.rgb, luminance); +} + +// https://learnopengl.com/Getting-started/Shaders \ No newline at end of file