Merge: roberto -> main
This commit is contained in:
45
src/main.c
Normal file → Executable file
45
src/main.c
Normal file → Executable file
@@ -3,7 +3,9 @@
|
||||
#include "data/axis.h"
|
||||
#include "data/shaders.h"
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <cglm/vec3.h>
|
||||
|
||||
#define WIDTH 512
|
||||
#define HEIGHT 512
|
||||
|
||||
@@ -16,10 +18,39 @@ unsigned char palette[] =
|
||||
0x7A,0x1C,0xAC,0xff,
|
||||
};
|
||||
|
||||
void calc_normal(float* v1, float* v2, float* v3, float* normal)
|
||||
{
|
||||
vec3 lado1, lado2;
|
||||
|
||||
glm_vec3_sub(v2, v1, lado1);
|
||||
glm_vec3_sub(v3, v1, lado2);
|
||||
|
||||
glm_vec3_cross(lado1, lado2, normal);
|
||||
glm_vec3_normalize(normal);
|
||||
}
|
||||
|
||||
float * fill_normal( float * d )
|
||||
{
|
||||
float * n;
|
||||
n = malloc( (*d+1)*sizeof(float));
|
||||
*n = *d;
|
||||
for (int i = 0; i < *d; i += 9)
|
||||
{
|
||||
|
||||
vec3 norm_vec;
|
||||
calc_normal((d+1)+i, (d+1)+i+3, (d+1)+i+6, norm_vec);
|
||||
glm_vec3_copy( norm_vec, (n+1)+i );
|
||||
glm_vec3_copy( norm_vec, (n+1)+i+3 );
|
||||
glm_vec3_copy( norm_vec, (n+1)+i+6 );
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
const char * wname = "manigraph: manifold grapher";
|
||||
|
||||
int main( void )
|
||||
{
|
||||
float * n_cube, *n_axis;
|
||||
id_t shader, texture;
|
||||
mesh_t m_cube, m_axis;
|
||||
window_t window;
|
||||
@@ -37,16 +68,22 @@ int main( void )
|
||||
|
||||
gload_program( shader, vs, VERTEX );
|
||||
gload_program( shader, fs, FRAGMENT );
|
||||
use_shader( shader );
|
||||
use_shader( shader );
|
||||
|
||||
load_fix_matrix( shader, (float)WIDTH/HEIGHT );
|
||||
|
||||
if( !( m_cube = create_mesh( d_cube ) ) )
|
||||
n_cube = fill_normal( d_cube );
|
||||
n_axis = fill_normal( d_axis );
|
||||
|
||||
if( !( m_cube = create_mesh( d_cube, n_cube ) ) )
|
||||
goto error_mesh_cube;
|
||||
|
||||
if( !( m_axis = create_mesh( d_axis ) ) )
|
||||
if( !( m_axis = create_mesh( d_axis, n_axis ) ) )
|
||||
goto error_mesh_axis;
|
||||
|
||||
free( n_cube );
|
||||
free( n_axis );
|
||||
|
||||
texture=create_palette_texture( palette );
|
||||
use_texture( texture );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user