diff --git a/include/base.h b/include/base.h index 6d3eeaf..24b7329 100644 --- a/include/base.h +++ b/include/base.h @@ -68,6 +68,7 @@ static inline char *read_file(char *filename) filesize = lseek(fd, 0, SEEK_END) + 1 ; contents = g_malloc(filesize * sizeof(char)); + assert (contents); lseek(fd, 0, SEEK_SET); read(fd,contents,filesize); diff --git a/include/graphics.h b/include/graphics.h index 0686350..a066de8 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -24,6 +24,7 @@ */ #pragma once +#include "base.h" #include #include #include @@ -223,6 +224,7 @@ static inline GLuint create_shader(int type, const char *src) 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", diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index 2dc9855..5077374 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -33,12 +33,46 @@ #define FRAG_SHADER_FILE "src/shaders/shader.frag" static GLuint arrows[] = { - 1, 0, 0, 0, 0, + 1, 0, 1, 2, 4, + 1, 1, 1, 2, 4, + 1, 2, 1, 2, 4, + 1, 3, 1, 2, 4, + 1, 4, 1, 2, 4, + 1, 5, 1, 2, 4, + 1, 1, 0, 0, 0, - 1, 2, 0, 0, 0, 1, 3, 0, 0, 0, - 1, 4, 0, 0, 0, 1, 5, 0, 0, 0, + + 1, 0, 2, 0, 0, + 1, 3, 2, 0, 0, + 1, 5, 2, 0, 0, + + 1, 1, 0, 4, 0, + 1, 2, 0, 4, 0, + 1, 5, 0, 4, 0, + + 1, 1, 0, 0, 6, + 1, 3, 0, 0, 6, + 1, 4, 0, 0, 6, + + 1, 0, 2, 4, 0, + 1, 2, 2, 4, 0, + 1, 5, 2, 4, 0, + + 1, 0, 2, 0, 6, + 1, 3, 2, 0, 6, + 1, 4, 2, 0, 6, + + 1, 1, 0, 4, 6, + 1, 2, 0, 4, 6, + 1, 4, 0, 4, 6, + + + 1, 0, 2, 4, 6, + 1, 2, 2, 4, 6, + 1, 4, 2, 4, 6, + // load, site, x, y, z }; @@ -130,9 +164,9 @@ static void graphics_debug_callback(GLenum source, GLenum type, GLuint id, static void get_model_data_and_user_preferences() { - model_space_size_x = 2; // 0 < model_space_size_x - model_space_size_y = 2; // 0 < model_space_size_y - model_space_size_z = 2; // 0 < model_space_size_z + model_space_size_x = 3; // 0 < model_space_size_x + model_space_size_y = 5; // 0 < model_space_size_y + model_space_size_z = 7; // 0 < model_space_size_z model_arrows_nb = sizeof(arrows) / (5 * 4); // assert : l'emplacement des flèches est contraint @@ -188,7 +222,7 @@ void graphics_write_vertex (GLfloat x, GLfloat y, GLfloat z) buffer_vertex_size += 3; - printf("Created vertex (%f,%f,%f), size is %d\n", x,y,z, buffer_vertex_size); + //printf("Created vertex (%f,%f,%f), size is %d\n", x,y,z, buffer_vertex_size); } /* @@ -259,7 +293,7 @@ void graphics_init_buffers(const void *gl_area) // colors glGenBuffers(1, &color_buffer); glBindBuffer(GL_ARRAY_BUFFER, color_buffer); - glBufferData(GL_ARRAY_BUFFER, buffer_colors_size * sizeof(buffer_colors_origin), buffer_colors_origin, GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, buffer_colors_size * sizeof(buffer_colors_origin[0]), buffer_colors_origin, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); // We only use one VAO, so we always keep it bound @@ -343,6 +377,7 @@ bool graphics_init_shaders(const void *gl_area) 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); @@ -539,12 +574,14 @@ bool graphics_init(const char *gl_area) // If it does not exist, allocs it if (gl_area_array == NULL) { gl_area_array = g_malloc0(sizeof(struct gl_area_entry *) * 2); + assert(gl_area_array); // If it does exist, g_reallocs it } else { gl_area_array = g_realloc(gl_area_array, (array_size + 1) * sizeof(struct gl_area_entry *)); + assert (gl_area_array); if (gl_area_array == NULL) { perror("Not enough memory to allocate gl_area_array"); return false; @@ -556,6 +593,7 @@ bool graphics_init(const char *gl_area) // Alloc new entry gl_area_array[array_size] = g_malloc0(sizeof(struct gl_area_entry)); + assert(gl_area_array[array_size]); strcpy(gl_area_array[array_size]->name, gl_area); @@ -599,6 +637,7 @@ bool graphics_shutdown(const void *gl_area) gl_area_array = g_realloc(gl_area_array, (gl_area_size()) * sizeof(struct gl_area_entry *)); + assert (gl_area_array || !gl_area_size()); g_free(buffer_vertex_origin); g_free(buffer_colors_origin); @@ -649,8 +688,7 @@ void main_test_graphics (void) y = arrows[i * 5 + 3]; z = arrows[i * 5 + 4]; - printf("[%ld]\tsite = %d\tx = %ld\ty = %ld\tz = %ld\tstep x = %ld\tstep y = %ld\n", - site, i, x, y, z, stx, sty); + // printf("[%ld]\tsite = %d\tx = %ld\ty = %ld\tz = %ld\tstep x = %ld\tstep y = %ld\n", site, i, x, y, z, stx, sty); arrows_write_basis (offset_after_grid + 12 * (stx * x + sty * y + stz * z)); // XXX 1 + 12 ? @@ -683,6 +721,7 @@ void main_test_graphics (void) arrows, model_arrows_nb, pref_show_grid); + printf("main_test_graphics [ok]\n"); } diff --git a/src/graphics/grid.c b/src/graphics/grid.c index 63742d0..4c632bd 100644 --- a/src/graphics/grid.c +++ b/src/graphics/grid.c @@ -62,22 +62,37 @@ void grid_write_ridges (long x, long y, long z) { - long step_x = z * y, - step_y = z, + long step_x = (z + 1) * (y + 1), + step_y = z + 1, step_z = 1; - if (1) graphics_write_line (step_z * 0 + step_y * 0 + step_x * 0, step_z * 0 + step_y * 0 + step_x * x); - if (1) graphics_write_line (step_z * 0 + step_y * 0 + step_x * 0, step_z * 0 + step_y * y + step_x * 0); - if (1) graphics_write_line (step_z * 0 + step_y * 0 + step_x * 0, step_z * z + step_y * 0 + step_x * 0); - if (1) graphics_write_line (step_z * z + step_y * y + step_x * x, step_z * 0 + step_y * y + step_x * x); - if (1) graphics_write_line (step_z * z + step_y * y + step_x * x, step_z * z + step_y * y + step_x * 0); - if (1) graphics_write_line (step_z * z + step_y * y + step_x * x, step_z * z + step_y * 0 + step_x * x); - if (1) graphics_write_line (step_z * 0 + step_y * 0 + step_x * x, step_z * 0 + step_y * y + step_x * x); - if (1) graphics_write_line (step_z * 0 + step_y * 0 + step_x * x, step_z * z + step_y * 0 + step_x * x); - if (1) graphics_write_line (step_z * z + step_y * 0 + step_x * 0, step_z * z + step_y * y + step_x * 0); - if (1) graphics_write_line (step_z * 0 + step_y * y + step_x * 0, step_z * 0 + step_y * y + step_x * x); - if (1) graphics_write_line (step_z * 0 + step_y * y + step_x * 0, step_z * z + step_y * y + step_x * 0); - if (1) graphics_write_line (step_z * z + step_y * 0 + step_x * 0, step_z * z + step_y * 0 + step_x * x); + graphics_write_line (step_z * 0 + step_y * 0 + step_x * 0, + step_z * 0 + step_y * 0 + step_x * x); + graphics_write_line (step_z * 0 + step_y * 0 + step_x * 0, + step_z * 0 + step_y * y + step_x * 0); + graphics_write_line (step_z * 0 + step_y * 0 + step_x * 0, + step_z * z + step_y * 0 + step_x * 0); + + graphics_write_line (step_z * z + step_y * y + step_x * x, + step_z * 0 + step_y * y + step_x * x); + graphics_write_line (step_z * z + step_y * y + step_x * x, + step_z * z + step_y * y + step_x * 0); + graphics_write_line (step_z * z + step_y * y + step_x * x, + step_z * z + step_y * 0 + step_x * x); + + graphics_write_line (step_z * 0 + step_y * 0 + step_x * x, + step_z * 0 + step_y * y + step_x * x); + graphics_write_line (step_z * 0 + step_y * 0 + step_x * x, + step_z * z + step_y * 0 + step_x * x); + graphics_write_line (step_z * z + step_y * 0 + step_x * 0, + step_z * z + step_y * y + step_x * 0); + + graphics_write_line (step_z * 0 + step_y * y + step_x * 0, + step_z * 0 + step_y * y + step_x * x); + graphics_write_line (step_z * 0 + step_y * y + step_x * 0, + step_z * z + step_y * y + step_x * 0); + graphics_write_line (step_z * z + step_y * 0 + step_x * 0, + step_z * z + step_y * 0 + step_x * x); } /* @@ -120,7 +135,7 @@ void grid_write_y (long x, long y, long z) x ++; y ++; z ++; float calcul = 0; - for (int u = 0; u < y; u++) { + for (int u = 0; u < z; u++) { for (int w = 0; w < x; w ++){ calcul = step_x * w + step_z * u; graphics_write_line (calcul, calcul + step_x - step_y);