WIP: including > graph_area (from GG client)
This commit is contained in:
parent
4b352f326e
commit
9979d5f725
11
Makefile
11
Makefile
|
@ -1,12 +1,21 @@
|
|||
.PHONY: run clean install all
|
||||
.DELETE_ON_ERROR: $(BINDIR)/Getting_Started_with_GTK
|
||||
.DEFAULT_GOAL: all
|
||||
|
||||
NTHREADS= $(shell nproc)
|
||||
|
||||
CC=gcc
|
||||
CFLAGS=`pkg-config --cflags gtk4 gl glib-2.0`
|
||||
LDFLAGS=`pkg-config --libs gtk4 gl glib-2.0`
|
||||
WARNINGS = -Wall
|
||||
DEBUG = -ggdb -fno-omit-frame-pointer
|
||||
DEBUG = -ggdb -fno-omit-frame-pointer #-fdiagnostics-color=always -fsanitize=bounds -fstack-check
|
||||
OPTIMIZE = -O3
|
||||
INCLUDE= $(shell pkg-config --cflags glib-2.0 libxml-2.0 gtk4)
|
||||
LIBS= $(shell pkg-config --libs glib-2.0 libxml-2.0 gtk4) -lGL -lGLU -lm -lepoxy -lX11 -lGLEW
|
||||
|
||||
BINDIR=bin
|
||||
BUILDDIR=build
|
||||
SRCDIR=src
|
||||
|
||||
sources = $(shell find . -maxdepth 1 -type f -name "*.c")
|
||||
objects = $(patsubst %.c,%.o,$(sources))
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Gem-graph OpenGL experiments
|
||||
*
|
||||
* Desc: Base header
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <glib-2.0/glib.h>
|
||||
//#define G_APPLICATION_DEFAULT_FLAGS 0
|
||||
|
||||
enum { X_AXIS, Y_AXIS, Z_AXIS, N_AXIS }; // Graphical axis
|
||||
enum { HOME_MODE, RUN_MODE, EDIT_MODE, PRESENTATION_MODE, N_MODE }; // Gem-graph modes
|
||||
struct arrow_t { uint load; uint site; uint x; uint y; uint z; }; // describes an arrow
|
||||
static inline char *read_file(char *filename);
|
||||
|
||||
/* I'm standing on Earth (or any spinning spheroid) and looking towards its North pole, then :
|
||||
X - X = EAST - WEST = rouge - cyan
|
||||
Y - Y = ZENITH - NADIR = vert - magenta (fuschia)
|
||||
Z - Z = NORTH - SOUTH = bleu - jaune */
|
||||
|
||||
#define EAST 0 // + x rouge
|
||||
#define WEST 1 // - x cyan
|
||||
#define ZENITH 2 // + y vert
|
||||
#define NADIR 3 // - y magenta
|
||||
#define SOUTH 4 // + z bleu
|
||||
#define NORTH 5 // - z jaune
|
||||
|
||||
|
||||
/*
|
||||
* char *read_file(char *filename) reads a file from filename into a provided buffer
|
||||
*
|
||||
* @param filename, file name
|
||||
* contents, target ptr
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
static inline char *read_file(char *filename)
|
||||
{
|
||||
int fd;
|
||||
int filesize;
|
||||
char *contents;
|
||||
|
||||
fd = open(filename, O_RDONLY);
|
||||
if(fd < 0) {
|
||||
printf("Couldn't read file: %s\n",filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
filesize = lseek(fd, 0, SEEK_END) + 1 ;
|
||||
contents = g_malloc(filesize * sizeof(char));
|
||||
assert (contents);
|
||||
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
read(fd,contents,filesize);
|
||||
|
||||
contents[filesize-1] = '\0';
|
||||
|
||||
close(fd);
|
||||
|
||||
return contents;
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
callback.o: callback.c tree.h \
|
||||
/gnu/store/fkmpkdav2zmz1k72989bdgpdrfac7rz1-glib-2.78.0/include/glib-2.0/glib.h \
|
||||
display.h contain.h texts.h in_depth.h
|
Binary file not shown.
|
@ -134,6 +134,7 @@ GtkWidget *get_SPACE_VIEW_box(){
|
|||
|
||||
GtkBox *middle_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2));
|
||||
gtk_box_append (middle_box, GTK_WIDGET (get_image_ALL_SPACE()));
|
||||
////////////////////////// gtk_box_append (middle_box, GTK_WIDGET (get_GLArea()));
|
||||
gtk_box_append (middle_box, GTK_WIDGET (gtk_separator_new (GTK_ORIENTATION_VERTICAL)));
|
||||
gtk_box_append (middle_box, GTK_WIDGET (right_box));
|
||||
return GTK_WIDGET (middle_box);
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
contain.o: contain.c tree.h \
|
||||
/gnu/store/fkmpkdav2zmz1k72989bdgpdrfac7rz1-glib-2.78.0/include/glib-2.0/glib.h \
|
||||
display.h contain.h texts.h callback.h
|
|
@ -0,0 +1,3 @@
|
|||
display.o: display.c tree.h \
|
||||
/gnu/store/fkmpkdav2zmz1k72989bdgpdrfac7rz1-glib-2.78.0/include/glib-2.0/glib.h \
|
||||
display.h contain.h texts.h
|
|
@ -0,0 +1,323 @@
|
|||
/*
|
||||
* Gem-graph OpenGL experiments
|
||||
*
|
||||
* Desc: User interface functions
|
||||
*
|
||||
* 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 <unistd.h>
|
||||
#include <gtk-4.0/gtk/gtk.h>
|
||||
#include <glib-2.0/glib.h>
|
||||
|
||||
#include "base.h"
|
||||
//#include "ui.h"
|
||||
//#include "graphics.h"
|
||||
|
||||
struct stack_index_t {
|
||||
long stack_id;
|
||||
void *container_widget;
|
||||
void *gl_area;
|
||||
};
|
||||
|
||||
static struct stack_index_t *stack_index = NULL;
|
||||
size_t stack_index_size = 0;
|
||||
|
||||
|
||||
/*
|
||||
* Look for stack entry and returns stack_id
|
||||
*
|
||||
* @params container_widget, generally the GtkBox that contains the GLArea
|
||||
*
|
||||
* @returns stack_id
|
||||
*/
|
||||
long ui_get_graphic_stack(void *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) {
|
||||
return stack_index[i].stack_id;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Look for stack entry and returns stack_id
|
||||
*
|
||||
* @params container_widget, generally the GtkBox that contains the GLArea
|
||||
*
|
||||
* @returns stack_id
|
||||
*/
|
||||
long ui_is_graphic_stack_ready(void *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) {
|
||||
return stack_index[i].stack_id;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Look for stack entry and initializes OpenGL for it
|
||||
*
|
||||
* @params container_widget, generally the GtkBox that contains the GLArea
|
||||
*
|
||||
* @returns bool, true if success
|
||||
*/
|
||||
bool ui_init_graphic_stack(void *container_widget, GError *error_buffer)
|
||||
{
|
||||
//g_printerr("[debug] ui_init_graphic_stack()\n");
|
||||
|
||||
//g_printerr("[debug] ui_init_graphic_stack() : target is %p\n", container_widget);
|
||||
|
||||
// look for stack_index entry
|
||||
for (int i = 0; i < stack_index_size; i++) {
|
||||
//g_printerr("[debug] ui_init_graphic_stack() : i is %d\n", i);
|
||||
//g_printerr("[debug] ui_init_graphic_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] ui_init_graphic_stack() : stack_id is %d\n",
|
||||
//stack_index[i].stack_id);
|
||||
if (stack_index[i].stack_id >= 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Look for stack entry and shutdowns OpenGL for it
|
||||
*
|
||||
* @params container_widget, generally the GtkBox that contains the GLArea
|
||||
*
|
||||
* @returns bool, true if success
|
||||
*/
|
||||
bool ui_shutdown_graphic_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,
|
||||
////////////////////////// &error_buffer) == false) {
|
||||
////////////////////////// return false;
|
||||
////////////////////////// }
|
||||
stack_index[i].stack_id = 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void ui_clean_stack_index(void)
|
||||
{
|
||||
// look for stack_index entry
|
||||
for (int i = 0; i < stack_index_size; i++) {
|
||||
stack_index[i].stack_id = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Look for stack entry and triggers OpenGL for drawing
|
||||
*
|
||||
* @params container_widget, generally the GtkBox that contains the GLArea
|
||||
*
|
||||
* @returns bool, true if success
|
||||
*/
|
||||
bool ui_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);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Look for stack entry and triggers OpenGL for drawing
|
||||
*
|
||||
* @params container_widget, generally the GtkBox that contains the GLArea
|
||||
*
|
||||
* @returns bool, true if success
|
||||
*/
|
||||
bool ui_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;
|
||||
gtk_widget_queue_draw((GtkWidget*)(stack_index[i].gl_area));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Look for every stack entry and shutdowns OpenGL for it
|
||||
*
|
||||
* @params void
|
||||
*
|
||||
* @returns bool, true if success
|
||||
*/
|
||||
void ui_shutdown_all_graphic_stacks(void)
|
||||
{
|
||||
// look for stack_index entry
|
||||
for (int i = 0; i < stack_index_size; i++) {
|
||||
////////////////////////// graphics_shutdown(stack_index[i].stack_id, NULL);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates a slider widget
|
||||
*
|
||||
* @params axis, meaning which axis we're building (for label)
|
||||
*
|
||||
* @returns GtkWidget*, pointer to the new widget
|
||||
*/
|
||||
GtkWidget *create_axis_slider(int axis)
|
||||
{
|
||||
GtkWidget *box, *label, *slider;
|
||||
GtkAdjustment *adj;
|
||||
const char *text;
|
||||
|
||||
box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
|
||||
|
||||
switch (axis) {
|
||||
case X_AXIS:
|
||||
text = "X";
|
||||
break;
|
||||
|
||||
case Y_AXIS:
|
||||
text = "Y";
|
||||
break;
|
||||
|
||||
case Z_AXIS:
|
||||
text = "Z";
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
}
|
||||
|
||||
label = gtk_label_new(text);
|
||||
gtk_box_append(GTK_BOX(box), label);
|
||||
gtk_widget_set_visible (label, TRUE);
|
||||
|
||||
adj = gtk_adjustment_new(0.0, 0.0, 360.0, 1.0, 12.0, 0.0);
|
||||
////////////////////////// g_signal_connect(adj, "value-changed",
|
||||
////////////////////////// G_CALLBACK(on_axis_value_change),
|
||||
////////////////////////// (gpointer) label);
|
||||
slider = gtk_scale_new(GTK_ORIENTATION_HORIZONTAL, adj);
|
||||
gtk_box_append(GTK_BOX(box), slider);
|
||||
gtk_widget_set_hexpand(slider, TRUE);
|
||||
gtk_widget_set_visible (slider, TRUE);
|
||||
|
||||
gtk_widget_set_visible (box, TRUE);
|
||||
|
||||
return box;
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates GLArea and indexes it
|
||||
*
|
||||
* @params target_mode, meaning which ui_stack we're on
|
||||
* target_widget, meaning the box that will host the GLArea
|
||||
*
|
||||
* @returns bool, true if success
|
||||
*/
|
||||
bool ui_setup_glarea(int target_mode, GtkWidget *target_widget)
|
||||
{
|
||||
GtkWidget *gl_area;
|
||||
|
||||
////g_printerr("[debug] ui_setup_glarea()\n");
|
||||
|
||||
assert(target_widget);
|
||||
|
||||
////g_printerr("[debug] ui_setup_glarea() : target is %p\n", target_widget);
|
||||
|
||||
if (stack_index == NULL) {
|
||||
stack_index = g_malloc(sizeof(struct stack_index_t));
|
||||
stack_index_size = 1;
|
||||
} else {
|
||||
// look for stack_index entry
|
||||
for (int i = 0; i < stack_index_size; i++) {
|
||||
if (stack_index[i].container_widget == (void *)target_widget) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// create entry
|
||||
stack_index =
|
||||
g_realloc(stack_index,
|
||||
++stack_index_size * sizeof(struct stack_index_t));
|
||||
}
|
||||
|
||||
gl_area = GTK_WIDGET(gtk_gl_area_new());
|
||||
assert(gl_area);
|
||||
|
||||
//gtk_widget_set_size_request(gl_area, 1000, 1000);
|
||||
gtk_gl_area_set_auto_render(GTK_GL_AREA(gl_area), true);
|
||||
gtk_widget_set_hexpand(gl_area, TRUE);
|
||||
gtk_widget_set_vexpand(gl_area, TRUE);
|
||||
//gtk_widget_set_halign(gl_area, GTK_ALIGN_CENTER);
|
||||
//gtk_widget_set_valign(gl_area, GTK_ALIGN_CENTER);
|
||||
|
||||
// The main "draw" call for GtkGLArea
|
||||
////////////////////////// g_signal_connect(GTK_GL_AREA(gl_area),
|
||||
////////////////////////// "render",
|
||||
////////////////////////// G_CALLBACK(on_glarea_render), NULL);
|
||||
|
||||
////////////////////////// g_signal_connect(gl_area,
|
||||
////////////////////////// "realize",
|
||||
////////////////////////// G_CALLBACK(on_glarea_realize), NULL);
|
||||
|
||||
////////////////////////// g_signal_connect(gl_area,
|
||||
////////////////////////// "unrealize",
|
||||
////////////////////////// G_CALLBACK(on_glarea_unrealize), NULL);
|
||||
|
||||
stack_index[stack_index_size-1].container_widget =
|
||||
(void*)target_widget;
|
||||
|
||||
stack_index[stack_index_size-1].gl_area = (void*)gl_area;
|
||||
|
||||
////g_printerr("[debug] ui_setup_glarea() : set target to %p\n", target_widget);
|
||||
|
||||
////g_printerr("[debug] ui_setup_glarea() : stack_index (@0x%p) had %ld elements\n",
|
||||
//stack_index,
|
||||
//stack_index_size);
|
||||
|
||||
gtk_box_append(GTK_BOX(target_widget), gl_area);
|
||||
gtk_widget_set_visible (GTK_WIDGET (gl_area), TRUE);
|
||||
|
||||
// Create sliders
|
||||
for(int i = 0; i < N_AXIS; i++)
|
||||
gtk_box_append(GTK_BOX(target_widget), create_axis_slider(i));
|
||||
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
graph_area.o: graph_area.c \
|
||||
/gnu/store/fkmpkdav2zmz1k72989bdgpdrfac7rz1-glib-2.78.0/include/glib-2.0/glib.h \
|
||||
base.h
|
|
@ -0,0 +1,314 @@
|
|||
/*
|
||||
* Gem-graph OpenGL experiments
|
||||
*
|
||||
* Desc: OpenGL utils header
|
||||
*
|
||||
* Copyright (C) 2023 Arthur Menges <arthur.menges@a-lec.org>
|
||||
* Copyright (C) 2023 Adrien Bourmault <neox@a-lec.org>
|
||||
* Copyright (C) 2023 Jean Sirmai <jean@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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "base.h"
|
||||
#include <unistd.h>
|
||||
#include <stdbool.h>
|
||||
#include <epoxy/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <GL/glext.h>
|
||||
#include <cglm/cglm.h>
|
||||
|
||||
#define VERTEX_SHADER_FILE "src/graphics/shaders/shader.vert"
|
||||
#define FRAG_SHADER_FILE "src/graphics/shaders/shader.frag"
|
||||
#define GL_TARGET_MAJOR_VERSION 0
|
||||
#define GL_TARGET_MINOR_VERSION 4
|
||||
|
||||
/*
|
||||
* Structure describing a gl_area and its parameters, used to create a table
|
||||
* of Gem-graph client current gl_areas
|
||||
*/
|
||||
struct graphic_stack_t {
|
||||
|
||||
int id;
|
||||
int mode;
|
||||
|
||||
float rotation_angles[N_AXIS]; // Rotation angles on each axis
|
||||
|
||||
GLuint vao; // init_buffers
|
||||
GLuint position_buffer; // shutdown, draw
|
||||
GLuint color_buffer; // shutdown, draw
|
||||
GLuint program; // shutdown, init_shaders, draw
|
||||
GLuint m; // init_shaders, draw
|
||||
GLuint v; // init_shaders, draw
|
||||
GLuint p; // init_shaders, draw
|
||||
|
||||
struct arrow_t *arrows_ptr;
|
||||
long arrows_nb;
|
||||
|
||||
GLfloat *buffer_vertex_origin;
|
||||
GLfloat *buffer_colors_origin;
|
||||
GLuint *buffer_lines_origin;
|
||||
GLuint *buffer_plans_origin;
|
||||
|
||||
long buffer_vertex_size;
|
||||
long buffer_colors_size;
|
||||
long buffer_lines_size;
|
||||
long buffer_plans_size;
|
||||
|
||||
long buffer_vertex_0_arrow;
|
||||
long buffer_colors_0_arrow;
|
||||
long buffer_lines_0_arrow;
|
||||
long buffer_plans_0_arrow;
|
||||
};
|
||||
|
||||
/*
|
||||
* Dynamic array of ptrs to dynamically allocated gl_area_entry
|
||||
*/
|
||||
extern struct graphic_stack_t *graphic_stack;
|
||||
|
||||
/*
|
||||
* Initializes a gl_area
|
||||
*
|
||||
* @param gl_area, ptr to the gl_area widget
|
||||
*
|
||||
* @return true if initialized
|
||||
*/
|
||||
int graphics_init(void *error_buffer);
|
||||
|
||||
/*
|
||||
* Draws the current buffer to a gl_area
|
||||
*
|
||||
* @param gl_area, ptr to the gl_area widget
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
void graphics_draw(const int stack_id);
|
||||
|
||||
/*
|
||||
* Shutdowns a gl_area
|
||||
*
|
||||
* @param gl_area, ptr to the gl_area widget
|
||||
*
|
||||
* @return true if success
|
||||
*/
|
||||
bool graphics_shutdown(const int stack_id, void *error_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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/*
|
||||
* Draws a vertex (x, y, z)
|
||||
* if (console) prints (x, y, z) values to console
|
||||
*
|
||||
* @param GLfloat x, GLfloat y, GLfloat z
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
void graphics_draw_vertex (const int stack_id,
|
||||
GLfloat x,
|
||||
GLfloat y,
|
||||
GLfloat z);
|
||||
|
||||
/*
|
||||
* Draws the color (r, g, b) associated to a vertex
|
||||
* if (console) prints (r, g, b) values to console
|
||||
*
|
||||
* @param GLfloat r, GLfloat g, GLfloat b
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
void graphics_draw_color (const int stack_id, GLfloat r, GLfloat g, GLfloat b);
|
||||
|
||||
/*
|
||||
* Writes values to describe a line from a to b into the line buffer
|
||||
*
|
||||
* @param coords GLuint (a,b)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
void graphics_draw_line (const int stack_id, GLuint a, GLuint b);
|
||||
|
||||
/*
|
||||
* Writes values to describe an (a,b,c) plan (triangle) into the plan buffer
|
||||
*
|
||||
* @param coords GLuint (a,b,c)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
void graphics_draw_plan (const int stack_id, GLuint a, GLuint b, GLuint c);
|
||||
|
||||
/*
|
||||
* Created and compile a shader
|
||||
*
|
||||
* @param type, shader type
|
||||
* src, source code of shader
|
||||
*
|
||||
* @return shader id
|
||||
*/
|
||||
static inline GLuint create_shader(const int stack_id, int type, const char *src)
|
||||
{
|
||||
GLuint shader;
|
||||
int status;
|
||||
|
||||
shader = glCreateShader(type);
|
||||
glShaderSource(shader, 1, &src, NULL);
|
||||
glCompileShader(shader);
|
||||
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
|
||||
if(status == GL_FALSE) {
|
||||
int log_len;
|
||||
char *buffer;
|
||||
|
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_len);
|
||||
|
||||
buffer = g_malloc(log_len + 1);
|
||||
assert (buffer);
|
||||
glGetShaderInfoLog(shader, log_len, NULL, buffer);
|
||||
|
||||
g_warning("Compile failure in %s shader:\n%s",
|
||||
type == GL_VERTEX_SHADER ? "vertex" : "fragment",
|
||||
buffer);
|
||||
|
||||
g_free(buffer);
|
||||
|
||||
glDeleteShader(shader);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
static inline void print_stack(int 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);
|
||||
|
||||
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("\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("arrows_ptr = %p\n", graphic_stack[stack_id].arrows_ptr);
|
||||
printf("arrows_nb = %ld\n", graphic_stack[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_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_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("********************\n");
|
||||
n++;
|
||||
}
|
||||
|
||||
|
||||
void graphics_model_setup (const int stack_id);
|
||||
|
||||
int draw_one_arrow_vertex (const int stack_id,
|
||||
int space_X,
|
||||
int space_Y,
|
||||
int space_Z,
|
||||
int weight,
|
||||
int site,
|
||||
int x,
|
||||
int y,
|
||||
int z);
|
||||
|
||||
int draw_one_arrow_line(const int stack_id,
|
||||
int offset_vertex);
|
||||
|
||||
/*
|
||||
* Writes grid ridges to vertex and color buffers
|
||||
*
|
||||
* @param coords long (x,y,z), step_x, step_y, step_z
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
int draw_space_ridges_vertex (const int stack_id,
|
||||
long offset_vertex,
|
||||
long x,
|
||||
long y,
|
||||
long z);
|
||||
|
||||
int draw_space_ridges_lines (const int stack_id);
|
||||
|
||||
/*
|
||||
* Writes grid lines on space faces
|
||||
*
|
||||
* @param coords long (x,y,z)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
long draw_grids_on_space_faces_vertex (const int stack_id,
|
||||
long x,
|
||||
long y,
|
||||
long z);
|
||||
|
||||
long draw_grids_on_space_faces_lines (const int stack_id,
|
||||
long offset_vertex,
|
||||
long x,
|
||||
long y,
|
||||
long z);
|
||||
|
||||
int set_arrow (int stack_id,
|
||||
int arrows_nb,
|
||||
int space_X,
|
||||
int space_Y,
|
||||
int space_Z,
|
||||
int requested_weight,
|
||||
int site,
|
||||
int arrow_x,
|
||||
int arrow_y,
|
||||
int arrow_z);
|
||||
|
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
in_depth.o: in_depth.c callback.h
|
Binary file not shown.
Loading…
Reference in New Issue