Add .clang-format and .gitignore

This commit is contained in:
PedroEdiaz
2024-10-24 11:21:07 -06:00
parent 2a5a101080
commit 3e27f0d165
11 changed files with 315 additions and 318 deletions

19
.clang-format Normal file
View File

@@ -0,0 +1,19 @@
---
PointerAlignment: Right
AllowShortBlocksOnASingleLine: Never
UseTab: Always
IndentWidth: 4
TabWidth: 4
ColumnLimit: 80
AlignAfterOpenBracket: false
AlignOperands: AlignAfterOperator
AlwaysBreakBeforeMultilineStrings: true
BreakBeforeBraces: Allman
BreakStringLiterals: true
IndentCaseLabels: false
IndentGotoLabels: false
InsertBraces: false
...

5
.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
manigraph
**.o
**.so
**.exe
**.dll

View File

@@ -8,12 +8,6 @@ void set_clean_color_context( unsigned char r, unsigned char g, unsigned char b
glClearColor((float)r / 0xff, (float)g / 0xff, (float)b / 0xff, 1.0);
}
int init_context( void )
{
return glewInit() == GLEW_OK;
}
int init_context(void) { return glewInit() == GLEW_OK; }
void clean_context( void )
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
}
void clean_context(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); }

View File

@@ -1,6 +1,6 @@
#include "main.h"
#include <cglm/quat.h>
#include <GLFW/glfw3.h>
#include <cglm/quat.h>
#include <stdio.h>
#define ANGLE ((float)0x01 / 0xff * 2 * GLM_PI)
@@ -11,8 +11,7 @@ int window_height;
versor q = GLM_QUAT_IDENTITY_INIT;
vec3 axis[3] =
{
vec3 axis[3] = {
{1, 0, 0},
{0, 1, 0},
{0, 0, 1},
@@ -20,12 +19,12 @@ vec3 axis[3] =
extern struct projection projection;
void __key_callback_input(GLFWwindow * window, int key, int scancode, int action, int mods )
void __key_callback_input(
GLFWwindow *window, int key, int scancode, int action, int mods)
{
if (action != GLFW_PRESS)
return;
if (GLFW_KEY_0 < key && key <= GLFW_KEY_9)
{
unsigned char selected_coord;
@@ -70,8 +69,6 @@ void __key_callback_input(GLFWwindow * window, int key, int scancode, int action
set_projection_mesh(projection);
return;
}
void __window_callback_input(GLFWwindow *window, int w, int h)
@@ -85,7 +82,8 @@ void __window_callback_input(GLFWwindow * window, int w, int h)
glViewport((w - m) / 2, (h - m) / 2, m, m);
}
void __mouse_callback_input(GLFWwindow* window, int button, int action, int mods)
void __mouse_callback_input(
GLFWwindow *window, int button, int action, int mods)
{
unsigned char green_value;
double xpos, ypos;
@@ -161,4 +159,3 @@ end:
glm_quat_normalize(q);
return q;
}

30
src/main.c Executable file → Normal file
View File

@@ -2,8 +2,8 @@
#include "data/axis.h"
#include "data/shaders.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#define WIDTH 512
#define HEIGHT 512
@@ -11,18 +11,28 @@
float *generate_data_surface(unsigned int, unsigned char *);
float *generate_normals_surface(float *, unsigned char);
unsigned char palette[] =
{
0xEB,0xD3,0xF8,0xff,
0xEB,0xD4,0xF8,0xff,
0xEB,0xD5,0xF8,0xff,
0x7A,0x1C,0xAC,0xff,
unsigned char palette[] = {
0xEB,
0xD3,
0xF8,
0xff,
0xEB,
0xD4,
0xF8,
0xff,
0xEB,
0xD5,
0xF8,
0xff,
0x7A,
0x1C,
0xAC,
0xff,
};
const char *wname = "manigraph: manifold grapher";
struct projection projection =
{
struct projection projection = {
.x = 0,
.y = 1,
.z = 2,
@@ -112,7 +122,6 @@ int main( void )
free(n_surface);
free(d_surface);
}
mlog("[MESH] Inicializando...\n");
@@ -164,7 +173,6 @@ int main( void )
close_window(window);
return 0;
mlog("[MESH] Destruyendo...\n");
destroy_mesh(m_axis);
error_mesh_axis:

View File

@@ -1,10 +1,9 @@
#include "main.h"
#include <cglm/mat4.h>
#include <cglm/cam.h>
#include <cglm/mat4.h>
#include <cglm/quat.h>
mat4 ortho[] =
{
mat4 ortho[] = {
{
{1, 0, 0, 0},
{0, 1, 0, 0},

9
src/mesh.c Executable file → Normal file
View File

@@ -1,7 +1,7 @@
#include "main.h"
#include <GL/glew.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
struct obj
{
@@ -57,8 +57,8 @@ mesh_t create_mesh( float * d, float * n, unsigned char m )
glGenBuffers(1, &p->d_vbo);
glBindBuffer(GL_ARRAY_BUFFER, p->d_vbo);
glBufferData( GL_ARRAY_BUFFER, p->vertex*m*sizeof(float), d+1,
GL_STATIC_DRAW );
glBufferData(
GL_ARRAY_BUFFER, p->vertex * m * sizeof(float), d + 1, GL_STATIC_DRAW);
if (n)
{
@@ -75,8 +75,7 @@ mesh_t create_mesh( float * d, float * n, unsigned char m )
}
{
struct projection projection =
{
struct projection projection = {
.x = 0,
.y = 1,
.z = 2,

View File

@@ -5,31 +5,18 @@
#include <stdio.h>
#endif
void destroy_shader( unsigned int shader )
{
return glDeleteProgram( shader );
}
void destroy_shader(unsigned int shader) { return glDeleteProgram(shader); }
unsigned int create_shader( void )
{
return glCreateProgram();
}
unsigned int create_shader(void) { return glCreateProgram(); }
void use_shader( unsigned int program )
{
return glUseProgram( program );
}
void use_shader(unsigned int program) { return glUseProgram(program); }
unsigned char load_program_to_shader( unsigned int program, const char * src,
unsigned int i )
unsigned char load_program_to_shader(
unsigned int program, const char *src, unsigned int i)
{
int shader, status;
unsigned int type[] =
{
[VERTEX]=GL_VERTEX_SHADER,
[FRAGMENT]=GL_FRAGMENT_SHADER
};
unsigned int type[] = {
[VERTEX] = GL_VERTEX_SHADER, [FRAGMENT] = GL_FRAGMENT_SHADER};
if (!src)
return 0;

View File

@@ -9,7 +9,6 @@
#define M_PI 3.14159265358979323846
#endif
void mobius(float *d_surface, int i, int j, int grid_size)
{
const float width = 0.5;
@@ -57,7 +56,6 @@ float * generate_data_surface(int grid_size, unsigned char *m )
d_surface = malloc((size + 1) * sizeof(float));
d_surface[0] = size;
for (i = 0; i < grid_size; i++)
{
for (j = 0; j < grid_size; j++)
@@ -83,8 +81,8 @@ float * generate_data_surface(int grid_size, unsigned char *m )
return d_surface;
}
static
void __calculate_normal(float* p1, float* p2, float* p3,float* normal, unsigned char n)
static void __calculate_normal(
float *p1, float *p2, float *p3, float *normal, unsigned char n)
{
float alpha;
vec4 v1, v2, v3;
@@ -104,11 +102,10 @@ void __calculate_normal(float* p1, float* p2, float* p3,float* normal, unsigned
case 4:
/*
In Grant-Shmidth we need 3 linearly independian vector that forms a basis,
so we can have a ortonormal version of that basis, since, we must have
v1 = p3 - p1
v2 = p2 - p1
Then v3 = p1, will most certantly be linerly independiant to v1 and v2.
In Grant-Shmidth we need 3 linearly independian vector that forms a
basis, so we can have a ortonormal version of that basis, since, we
must have v1 = p3 - p1 v2 = p2 - p1 Then v3 = p1, will most certantly
be linerly independiant to v1 and v2.
*/
glm_vec4_sub(p2, p1, v1);
glm_vec4_sub(p3, p1, v2);
@@ -159,11 +156,11 @@ float * generate_normals_surface( float * d, unsigned char m )
vec4 norm_vec;
__calculate_normal((d+1)+i, (d+1)+i+m, (d+1)+i+2*m, norm_vec, m);
__calculate_normal(
(d + 1) + i, (d + 1) + i + m, (d + 1) + i + 2 * m, norm_vec, m);
glm_vec3_copy(norm_vec, (n + 1) + i);
glm_vec3_copy(norm_vec, (n + 1) + i + m);
glm_vec3_copy(norm_vec, (n + 1) + i + 2 * m);
}
return n;
}

View File

@@ -3,8 +3,7 @@
#define TYPE GL_TEXTURE_2D_ARRAY
static
id_t __config_texture( unsigned short type )
static id_t __config_texture(unsigned short type)
{
id_t texture;
@@ -19,10 +18,7 @@ id_t __config_texture( unsigned short type )
return texture;
}
void use_texture( id_t texture )
{
return glBindTexture( TYPE, texture );
}
void use_texture(id_t texture) { return glBindTexture(TYPE, texture); }
void destroy_texture(unsigned int texture)
{
@@ -32,7 +28,7 @@ void destroy_texture( unsigned int texture )
id_t create_palette_texture(const unsigned char *colors, unsigned char n)
{
id_t texture = __config_texture(TYPE);
glTexImage3D( TYPE, 0, GL_RGBA,
1, 1, n, 0, GL_RGBA, GL_UNSIGNED_BYTE, colors);
glTexImage3D(
TYPE, 0, GL_RGBA, 1, 1, n, 0, GL_RGBA, GL_UNSIGNED_BYTE, colors);
return texture;
}

View File

@@ -16,8 +16,7 @@ window_t init_window(unsigned int w, unsigned int h, const char * name);
para lograr los fps deseados.
*/
static
void __limit_fps_window(int max_fps)
static void __limit_fps_window(int max_fps)
{
static double previous_time = 0.0;
double current_time;
@@ -71,10 +70,7 @@ window_t init_window(unsigned int width, unsigned int height, const char *title)
return window;
}
void use_window(window_t window)
{
glfwMakeContextCurrent((void*)window);
}
void use_window(window_t window) { glfwMakeContextCurrent((void *)window); }
int is_open_window(window_t window)
{