WIP: je comprends pas que ça marche, là ? (draw_space_... draw_grids_... in graph_stack (288))

This commit is contained in:
Jean Sirmai 2024-06-06 10:52:41 +02:00
parent b9cb86c17c
commit 9734c9b2af
Signed by: jean
GPG Key ID: FB3115C340E057E3
3 changed files with 195 additions and 8 deletions

20
(notes)
View File

@ -1,27 +1,39 @@
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.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: (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: (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, "realize", G_CALLBACK(on_glarea_realize), NULL);
graph_area.c: g_signal_connect(gl_area, "unrealize", G_CALLBACK(on_glarea_unrealize), 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);
graph_stack.c: (149) if (!graphics_init_shaders(cur_id)) return -1; graph_stack.c: (149) if (!graphics_init_shaders(cur_id)) return -1;
graph_stack.c: (153) graphics_init_buffers(cur_id); 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: (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_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_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: 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: (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);
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
https://docs.gtk.org/gtk4/visual_index.html widgets gallery https://docs.gtk.org/gtk4/visual_index.html widgets gallery
https://forge.a-lec.org/gem-graph/gem-graph-client/src/branch/devel/Makefile https://forge.a-lec.org/gem-graph/gem-graph-client/src/branch/devel/Makefile
https://docs.gtk.org/gtk4/class.Widget.html#height-for-width-geometry-management https://docs.gtk.org/gtk4/class.Widget.html#height-for-width-geometry-management

View File

@ -285,10 +285,10 @@ 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_vertex (stack_id, stack->buffer_vertex_size, space_X, space_Y, space_Z);
////////////////////////// draw_space_ridges_lines (stack_id); 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_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); draw_grids_on_space_faces_lines (stack_id, stack->buffer_lines_size, space_X, space_Y, space_Z);
stack->buffer_vertex_0_arrow = stack->buffer_vertex_size; stack->buffer_vertex_0_arrow = stack->buffer_vertex_size;
stack->buffer_colors_0_arrow = stack->buffer_colors_size; stack->buffer_colors_0_arrow = stack->buffer_colors_size;

175
init.c Normal file
View File

@ -0,0 +1,175 @@
/*
* Gem-graph OpenGL experiments
*
* Desc: GL functions
*
* Copyright (C) 2023 Arthur Menges <arthur.menges@a-lec.org>
* Copyright (C) 2023 Adrien Bourmault <neox@a-lec.org>
*
* 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 published by
* 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 <http://www.gnu.org/licenses/>.
*/
/* -------------------------------------------------------------------------- */
#include <stdlib.h>
#include <time.h>
#include "base.h"
#include "contain.h" // instead of "ui.h"
#include "graph_area.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)
{
struct graphic_stack_t *stack = &graphic_stack[stack_id];
//XXX
graphics_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,
GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
// 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,
GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
// We only use one VAO, so we always keep it bound
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
stack->vao = vao;
stack->position_buffer = vertex_buffer;
stack->color_buffer = color_buffer;
}
/*
* Initializes the shaders of a gl_area and link them to a program
*
* @param gl_area, ptr to the gl_area widget
*
* @return true if initialized
*/
bool graphics_init_shaders(const int stack_id)
{
struct graphic_stack_t *stack = &graphic_stack[stack_id];
char *vertex_shader;
char *fragment_shader;
int status;
GLuint vertex = 0, fragment; // 2024-06-05 j'initialise vertex à 0 (au pif !)
GLuint program = 0;
GLuint m = 0;
GLuint v = 0;
GLuint p = 0;
// Load vertex shader file
vertex_shader = read_file(VERTEX_SHADER_FILE);
if (vertex_shader == NULL)
return false;
vertex = create_shader(stack_id, GL_VERTEX_SHADER, vertex_shader);
if(vertex == 0) {
stack->program = 0;
g_free(vertex_shader);
return false;
}
// Load fragment shader file
fragment_shader = read_file(FRAG_SHADER_FILE);
if (fragment_shader == NULL)
return false;
fragment = create_shader(stack_id, GL_FRAGMENT_SHADER, fragment_shader);
if(fragment == 0) {
glDeleteShader(vertex);
stack->program = 0;
g_free(vertex_shader);
g_free(fragment_shader);
return false;
}
// Link shaders to program
program = glCreateProgram();
glAttachShader(program, vertex);
glAttachShader(program, fragment);
glLinkProgram(program);
glGetProgramiv(program, GL_LINK_STATUS, &status);
if(status == GL_FALSE) {
int log_len;
char *buffer;
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &log_len);
buffer = g_malloc(log_len + 1);
assert(buffer);
glGetProgramInfoLog(program, log_len, NULL, buffer);
g_warning("Linking failure:\n%s", buffer);
g_free(buffer);
glDeleteProgram(program);
program = 0;
glDeleteShader(vertex);
glDeleteShader(fragment);
g_free(vertex_shader);
g_free(fragment_shader);
return false;
}
/* Get the location of the "mvp" uniform */
m = glGetUniformLocation(program, "model_matrix");
v = glGetUniformLocation(program, "view_matrix");
p = glGetUniformLocation(program, "projection_matrix");
glDetachShader(program, vertex);
glDetachShader(program, fragment);
glDeleteShader(vertex);
glDeleteShader(fragment);
stack->program = program;
stack->m = m;
stack->v = v;
stack->p = p;
g_free(vertex_shader);
g_free(fragment_shader);
return true;
}