Add .clang-format and .gitignore
This commit is contained in:
19
.clang-format
Normal file
19
.clang-format
Normal 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
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
manigraph
|
||||||
|
**.o
|
||||||
|
**.so
|
||||||
|
**.exe
|
||||||
|
**.dll
|
||||||
@@ -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);
|
glClearColor((float)r / 0xff, (float)g / 0xff, (float)b / 0xff, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int init_context( void )
|
int init_context(void) { return glewInit() == GLEW_OK; }
|
||||||
{
|
|
||||||
return glewInit() == GLEW_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
void clean_context( void )
|
void clean_context(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); }
|
||||||
{
|
|
||||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
|
||||||
}
|
|
||||||
|
|||||||
15
src/input.c
15
src/input.c
@@ -1,6 +1,6 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include <cglm/quat.h>
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <cglm/quat.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define ANGLE ((float)0x01 / 0xff * 2 * GLM_PI)
|
#define ANGLE ((float)0x01 / 0xff * 2 * GLM_PI)
|
||||||
@@ -11,8 +11,7 @@ int window_height;
|
|||||||
|
|
||||||
versor q = GLM_QUAT_IDENTITY_INIT;
|
versor q = GLM_QUAT_IDENTITY_INIT;
|
||||||
|
|
||||||
vec3 axis[3] =
|
vec3 axis[3] = {
|
||||||
{
|
|
||||||
{1, 0, 0},
|
{1, 0, 0},
|
||||||
{0, 1, 0},
|
{0, 1, 0},
|
||||||
{0, 0, 1},
|
{0, 0, 1},
|
||||||
@@ -20,12 +19,12 @@ vec3 axis[3] =
|
|||||||
|
|
||||||
extern struct projection projection;
|
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)
|
if (action != GLFW_PRESS)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
if (GLFW_KEY_0 < key && key <= GLFW_KEY_9)
|
if (GLFW_KEY_0 < key && key <= GLFW_KEY_9)
|
||||||
{
|
{
|
||||||
unsigned char selected_coord;
|
unsigned char selected_coord;
|
||||||
@@ -70,8 +69,6 @@ void __key_callback_input(GLFWwindow * window, int key, int scancode, int action
|
|||||||
|
|
||||||
set_projection_mesh(projection);
|
set_projection_mesh(projection);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void __window_callback_input(GLFWwindow *window, int w, int h)
|
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);
|
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;
|
unsigned char green_value;
|
||||||
double xpos, ypos;
|
double xpos, ypos;
|
||||||
@@ -161,4 +159,3 @@ end:
|
|||||||
glm_quat_normalize(q);
|
glm_quat_normalize(q);
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
30
src/main.c
Executable file → Normal file
30
src/main.c
Executable file → Normal file
@@ -2,8 +2,8 @@
|
|||||||
#include "data/axis.h"
|
#include "data/axis.h"
|
||||||
#include "data/shaders.h"
|
#include "data/shaders.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define WIDTH 512
|
#define WIDTH 512
|
||||||
#define HEIGHT 512
|
#define HEIGHT 512
|
||||||
@@ -11,18 +11,28 @@
|
|||||||
float *generate_data_surface(unsigned int, unsigned char *);
|
float *generate_data_surface(unsigned int, unsigned char *);
|
||||||
float *generate_normals_surface(float *, unsigned char);
|
float *generate_normals_surface(float *, unsigned char);
|
||||||
|
|
||||||
unsigned char palette[] =
|
unsigned char palette[] = {
|
||||||
{
|
0xEB,
|
||||||
0xEB,0xD3,0xF8,0xff,
|
0xD3,
|
||||||
0xEB,0xD4,0xF8,0xff,
|
0xF8,
|
||||||
0xEB,0xD5,0xF8,0xff,
|
0xff,
|
||||||
0x7A,0x1C,0xAC,0xff,
|
0xEB,
|
||||||
|
0xD4,
|
||||||
|
0xF8,
|
||||||
|
0xff,
|
||||||
|
0xEB,
|
||||||
|
0xD5,
|
||||||
|
0xF8,
|
||||||
|
0xff,
|
||||||
|
0x7A,
|
||||||
|
0x1C,
|
||||||
|
0xAC,
|
||||||
|
0xff,
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *wname = "manigraph: manifold grapher";
|
const char *wname = "manigraph: manifold grapher";
|
||||||
|
|
||||||
struct projection projection =
|
struct projection projection = {
|
||||||
{
|
|
||||||
.x = 0,
|
.x = 0,
|
||||||
.y = 1,
|
.y = 1,
|
||||||
.z = 2,
|
.z = 2,
|
||||||
@@ -112,7 +122,6 @@ int main( void )
|
|||||||
|
|
||||||
free(n_surface);
|
free(n_surface);
|
||||||
free(d_surface);
|
free(d_surface);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mlog("[MESH] Inicializando...\n");
|
mlog("[MESH] Inicializando...\n");
|
||||||
@@ -164,7 +173,6 @@ int main( void )
|
|||||||
close_window(window);
|
close_window(window);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
mlog("[MESH] Destruyendo...\n");
|
mlog("[MESH] Destruyendo...\n");
|
||||||
destroy_mesh(m_axis);
|
destroy_mesh(m_axis);
|
||||||
error_mesh_axis:
|
error_mesh_axis:
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include <cglm/mat4.h>
|
|
||||||
#include <cglm/cam.h>
|
#include <cglm/cam.h>
|
||||||
|
#include <cglm/mat4.h>
|
||||||
#include <cglm/quat.h>
|
#include <cglm/quat.h>
|
||||||
|
|
||||||
mat4 ortho[] =
|
mat4 ortho[] = {
|
||||||
{
|
|
||||||
{
|
{
|
||||||
{1, 0, 0, 0},
|
{1, 0, 0, 0},
|
||||||
{0, 1, 0, 0},
|
{0, 1, 0, 0},
|
||||||
|
|||||||
9
src/mesh.c
Executable file → Normal file
9
src/mesh.c
Executable file → Normal file
@@ -1,7 +1,7 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
struct obj
|
struct obj
|
||||||
{
|
{
|
||||||
@@ -57,8 +57,8 @@ mesh_t create_mesh( float * d, float * n, unsigned char m )
|
|||||||
|
|
||||||
glGenBuffers(1, &p->d_vbo);
|
glGenBuffers(1, &p->d_vbo);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, p->d_vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, p->d_vbo);
|
||||||
glBufferData( GL_ARRAY_BUFFER, p->vertex*m*sizeof(float), d+1,
|
glBufferData(
|
||||||
GL_STATIC_DRAW );
|
GL_ARRAY_BUFFER, p->vertex * m * sizeof(float), d + 1, GL_STATIC_DRAW);
|
||||||
|
|
||||||
if (n)
|
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,
|
.x = 0,
|
||||||
.y = 1,
|
.y = 1,
|
||||||
.z = 2,
|
.z = 2,
|
||||||
|
|||||||
27
src/shader.c
27
src/shader.c
@@ -5,31 +5,18 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void destroy_shader( unsigned int shader )
|
void destroy_shader(unsigned int shader) { return glDeleteProgram(shader); }
|
||||||
{
|
|
||||||
return glDeleteProgram( shader );
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int create_shader( void )
|
unsigned int create_shader(void) { return glCreateProgram(); }
|
||||||
{
|
|
||||||
return glCreateProgram();
|
|
||||||
}
|
|
||||||
|
|
||||||
void use_shader( unsigned int program )
|
void use_shader(unsigned int program) { return glUseProgram(program); }
|
||||||
{
|
|
||||||
return glUseProgram( program );
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char load_program_to_shader( unsigned int program, const char * src,
|
unsigned char load_program_to_shader(
|
||||||
unsigned int i )
|
unsigned int program, const char *src, unsigned int i)
|
||||||
{
|
{
|
||||||
int shader, status;
|
int shader, status;
|
||||||
unsigned int type[] =
|
unsigned int type[] = {
|
||||||
{
|
[VERTEX] = GL_VERTEX_SHADER, [FRAGMENT] = GL_FRAGMENT_SHADER};
|
||||||
[VERTEX]=GL_VERTEX_SHADER,
|
|
||||||
[FRAGMENT]=GL_FRAGMENT_SHADER
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
if (!src)
|
if (!src)
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
#define M_PI 3.14159265358979323846
|
#define M_PI 3.14159265358979323846
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void mobius(float *d_surface, int i, int j, int grid_size)
|
void mobius(float *d_surface, int i, int j, int grid_size)
|
||||||
{
|
{
|
||||||
const float width = 0.5;
|
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 = malloc((size + 1) * sizeof(float));
|
||||||
d_surface[0] = size;
|
d_surface[0] = size;
|
||||||
|
|
||||||
|
|
||||||
for (i = 0; i < grid_size; i++)
|
for (i = 0; i < grid_size; i++)
|
||||||
{
|
{
|
||||||
for (j = 0; j < grid_size; j++)
|
for (j = 0; j < grid_size; j++)
|
||||||
@@ -83,8 +81,8 @@ float * generate_data_surface(int grid_size, unsigned char *m )
|
|||||||
return d_surface;
|
return d_surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static void __calculate_normal(
|
||||||
void __calculate_normal(float* p1, float* p2, float* p3,float* normal, unsigned char n)
|
float *p1, float *p2, float *p3, float *normal, unsigned char n)
|
||||||
{
|
{
|
||||||
float alpha;
|
float alpha;
|
||||||
vec4 v1, v2, v3;
|
vec4 v1, v2, v3;
|
||||||
@@ -104,11 +102,10 @@ void __calculate_normal(float* p1, float* p2, float* p3,float* normal, unsigned
|
|||||||
case 4:
|
case 4:
|
||||||
|
|
||||||
/*
|
/*
|
||||||
In Grant-Shmidth we need 3 linearly independian vector that forms a basis,
|
In Grant-Shmidth we need 3 linearly independian vector that forms a
|
||||||
so we can have a ortonormal version of that basis, since, we must have
|
basis, so we can have a ortonormal version of that basis, since, we
|
||||||
v1 = p3 - p1
|
must have v1 = p3 - p1 v2 = p2 - p1 Then v3 = p1, will most certantly
|
||||||
v2 = p2 - p1
|
be linerly independiant to v1 and v2.
|
||||||
Then v3 = p1, will most certantly be linerly independiant to v1 and v2.
|
|
||||||
*/
|
*/
|
||||||
glm_vec4_sub(p2, p1, v1);
|
glm_vec4_sub(p2, p1, v1);
|
||||||
glm_vec4_sub(p3, p1, v2);
|
glm_vec4_sub(p3, p1, v2);
|
||||||
@@ -159,11 +156,11 @@ float * generate_normals_surface( float * d, unsigned char m )
|
|||||||
|
|
||||||
vec4 norm_vec;
|
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);
|
||||||
glm_vec3_copy(norm_vec, (n + 1) + i + m);
|
glm_vec3_copy(norm_vec, (n + 1) + i + m);
|
||||||
glm_vec3_copy(norm_vec, (n + 1) + i + 2 * m);
|
glm_vec3_copy(norm_vec, (n + 1) + i + 2 * m);
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,7 @@
|
|||||||
|
|
||||||
#define TYPE GL_TEXTURE_2D_ARRAY
|
#define TYPE GL_TEXTURE_2D_ARRAY
|
||||||
|
|
||||||
static
|
static id_t __config_texture(unsigned short type)
|
||||||
id_t __config_texture( unsigned short type )
|
|
||||||
{
|
{
|
||||||
id_t texture;
|
id_t texture;
|
||||||
|
|
||||||
@@ -19,10 +18,7 @@ id_t __config_texture( unsigned short type )
|
|||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
void use_texture( id_t texture )
|
void use_texture(id_t texture) { return glBindTexture(TYPE, texture); }
|
||||||
{
|
|
||||||
return glBindTexture( TYPE, texture );
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroy_texture(unsigned int 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 create_palette_texture(const unsigned char *colors, unsigned char n)
|
||||||
{
|
{
|
||||||
id_t texture = __config_texture(TYPE);
|
id_t texture = __config_texture(TYPE);
|
||||||
glTexImage3D( TYPE, 0, GL_RGBA,
|
glTexImage3D(
|
||||||
1, 1, n, 0, GL_RGBA, GL_UNSIGNED_BYTE, colors);
|
TYPE, 0, GL_RGBA, 1, 1, n, 0, GL_RGBA, GL_UNSIGNED_BYTE, colors);
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,7 @@ window_t init_window(unsigned int w, unsigned int h, const char * name);
|
|||||||
para lograr los fps deseados.
|
para lograr los fps deseados.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static
|
static void __limit_fps_window(int max_fps)
|
||||||
void __limit_fps_window(int max_fps)
|
|
||||||
{
|
{
|
||||||
static double previous_time = 0.0;
|
static double previous_time = 0.0;
|
||||||
double current_time;
|
double current_time;
|
||||||
@@ -71,10 +70,7 @@ window_t init_window(unsigned int width, unsigned int height, const char *title)
|
|||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
void use_window(window_t window)
|
void use_window(window_t window) { glfwMakeContextCurrent((void *)window); }
|
||||||
{
|
|
||||||
glfwMakeContextCurrent((void*)window);
|
|
||||||
}
|
|
||||||
|
|
||||||
int is_open_window(window_t window)
|
int is_open_window(window_t window)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user