Final: Illumination
This commit is contained in:
8
Makefile
8
Makefile
@@ -38,6 +38,8 @@ help:
|
|||||||
@echo "Para ejecturar el programa sin instalarlos se puede usar:"
|
@echo "Para ejecturar el programa sin instalarlos se puede usar:"
|
||||||
@echo " $(MAKE) run-linux"
|
@echo " $(MAKE) run-linux"
|
||||||
|
|
||||||
|
src/main.o: src/data/axis.h src/data/cube.h src/data/shaders.h
|
||||||
|
|
||||||
# WINDOWS
|
# WINDOWS
|
||||||
windows: $(OBJ) glfw.dll
|
windows: $(OBJ) glfw.dll
|
||||||
$(CC) $(CFLAGS) $(OBJ) -o $(BIN) -L. -lglfw -lopengl32 -lglew32
|
$(CC) $(CFLAGS) $(OBJ) -o $(BIN) -L. -lglfw -lopengl32 -lglew32
|
||||||
@@ -62,15 +64,13 @@ cocoa: $(OBJ)
|
|||||||
$(MAKE) BKN=_GLFW_COCOA libglfw.so
|
$(MAKE) BKN=_GLFW_COCOA libglfw.so
|
||||||
$(CC) -framework OpenGL -o $(BIN) $(OBJ) -L. -lGLEW -lGL -lglfw
|
$(CC) -framework OpenGL -o $(BIN) $(OBJ) -L. -lGLEW -lGL -lglfw
|
||||||
|
|
||||||
libglfw.so: wayland.h
|
libglfw.so:
|
||||||
$(CC) -fPIC -shared -D$(BKN) -D_GLFW_BUILD_DLL -Iext/glfw/deps/wayland ./ext/glfw/src/*.c -o $@
|
|
||||||
|
|
||||||
wayland.h:
|
|
||||||
for i in $(WAYLAND-LIB); \
|
for i in $(WAYLAND-LIB); \
|
||||||
do \
|
do \
|
||||||
wayland-scanner client-header ext/glfw/deps/wayland/$$i.xml ext/glfw/deps/wayland/$$i-client-protocol.h; \
|
wayland-scanner client-header ext/glfw/deps/wayland/$$i.xml ext/glfw/deps/wayland/$$i-client-protocol.h; \
|
||||||
wayland-scanner private-code ext/glfw/deps/wayland/$$i.xml ext/glfw/deps/wayland/$$i-client-protocol-code.h; \
|
wayland-scanner private-code ext/glfw/deps/wayland/$$i.xml ext/glfw/deps/wayland/$$i-client-protocol-code.h; \
|
||||||
done
|
done
|
||||||
|
$(CC) -fPIC -shared -D$(BKN) -D_GLFW_BUILD_DLL -Iext/glfw/deps/wayland ./ext/glfw/src/*.c -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm $(OBJ) $(BIN) ext/glfw/deps/wayland/*.h
|
rm $(OBJ) $(BIN) ext/glfw/deps/wayland/*.h
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
void set_clean_color_context( unsigned char r, unsigned char g, unsigned char b )
|
void set_clean_color_context( unsigned char r, unsigned char g, unsigned char b )
|
||||||
{
|
{
|
||||||
glEnable( GL_DEPTH_TEST );
|
glEnable( GL_DEPTH_TEST );
|
||||||
|
glEnable( GL_CULL_FACE );
|
||||||
|
glCullFace( GL_BACK );
|
||||||
|
|
||||||
glClearColor( (float)r/0xff, (float)g/0xff, (float)b/0xff, 1.0 );
|
glClearColor( (float)r/0xff, (float)g/0xff, (float)b/0xff, 1.0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,39 +7,35 @@
|
|||||||
#undef G
|
#undef G
|
||||||
#undef H
|
#undef H
|
||||||
|
|
||||||
const float X = 2.0;
|
#define A -2.0,-0.05,-0.05,
|
||||||
const float Y = 0.05;
|
#define B -2.0,-0.05, 0.05,
|
||||||
const float Z = 0.05;
|
#define C -2.0, 0.05,-0.05,
|
||||||
|
#define D -2.0, 0.05, 0.05,
|
||||||
#define A -X,-Y,-Z,
|
#define E 2.0,-0.05,-0.05,
|
||||||
#define B -X,-Y, Z,
|
#define F 2.0,-0.05, 0.05,
|
||||||
#define C -X, Y,-Z,
|
#define G 2.0, 0.05,-0.05,
|
||||||
#define D -X, Y, Z,
|
#define H 2.0, 0.05, 0.05,
|
||||||
#define E X,-Y,-Z,
|
|
||||||
#define F X,-Y, Z,
|
|
||||||
#define G X, Y,-Z,
|
|
||||||
#define H X, Y, Z,
|
|
||||||
|
|
||||||
narray_float_t d_axis =
|
narray_float_t d_axis =
|
||||||
{
|
{
|
||||||
3*3*2*6,
|
3*3*2*6,
|
||||||
|
|
||||||
A C E
|
A C E
|
||||||
C E G
|
G E D
|
||||||
|
|
||||||
E G F
|
E G F
|
||||||
G F H
|
H F G
|
||||||
|
|
||||||
F H B
|
F H B
|
||||||
H B D
|
D B H
|
||||||
|
|
||||||
B D A
|
B D A
|
||||||
D A C
|
C A D
|
||||||
|
|
||||||
C D G
|
C D G
|
||||||
D G H
|
H G D
|
||||||
|
|
||||||
A B E
|
E B A
|
||||||
B E F
|
B E F
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#include <cglm/cglm.h>
|
|
||||||
|
|
||||||
#define A -1,-1,-1,
|
#define A -1,-1,-1,
|
||||||
#define B -1,-1, 1,
|
#define B -1,-1, 1,
|
||||||
#define C -1, 1,-1,
|
#define C -1, 1,-1,
|
||||||
@@ -9,43 +7,25 @@
|
|||||||
#define G 1, 1,-1,
|
#define G 1, 1,-1,
|
||||||
#define H 1, 1, 1,
|
#define H 1, 1, 1,
|
||||||
|
|
||||||
narray_float_t d_cube =
|
float d_cube[] =
|
||||||
{
|
{
|
||||||
3*3*2*6,
|
3*3*2*6,
|
||||||
|
|
||||||
A C E
|
A C E
|
||||||
C E G
|
G E C
|
||||||
|
|
||||||
E G F
|
E G F
|
||||||
G F H
|
H F G
|
||||||
|
|
||||||
F H B
|
F H B
|
||||||
H B D
|
D B H
|
||||||
|
|
||||||
B D A
|
B D A
|
||||||
D A C
|
C A D
|
||||||
|
|
||||||
C D G
|
C D G
|
||||||
D G H
|
H G D
|
||||||
|
|
||||||
A B E
|
E B A
|
||||||
B E F
|
|
||||||
|
|
||||||
A C E
|
|
||||||
C E G
|
|
||||||
|
|
||||||
E G F
|
|
||||||
G F H
|
|
||||||
|
|
||||||
F H B
|
|
||||||
H B D
|
|
||||||
|
|
||||||
B D A
|
|
||||||
D A C
|
|
||||||
|
|
||||||
C D G
|
|
||||||
D G H
|
|
||||||
|
|
||||||
A B E
|
|
||||||
B E F
|
B E F
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -37,14 +37,12 @@ const char * fs =
|
|||||||
"{"
|
"{"
|
||||||
|
|
||||||
" vec4 color = texture( palette, vec3( 0, 0, index ) ).rgba;"
|
" vec4 color = texture( palette, vec3( 0, 0, index ) ).rgba;"
|
||||||
" vec3 lightColor = vec3(1,1,1);"
|
" vec3 lightPos = vec3(0,0,-15);"
|
||||||
" vec3 lightPos = vec3(0,000,-15);"
|
|
||||||
" vec3 lightDir = normalize(lightPos - FragPos);"
|
" vec3 lightDir = normalize(lightPos - FragPos);"
|
||||||
" vec3 norm = normalize(Normal);"
|
|
||||||
|
|
||||||
" float diffuse = max(dot(norm, lightDir), 0.0);"
|
" float diffuse = max(dot(Normal, lightDir), 0.0);"
|
||||||
" float ambient = 0.5;"
|
" float ambient = 0.5;"
|
||||||
" FragColor = vec4((ambient + diffuse)*lightColor,1.0)*color;"
|
" FragColor = (ambient + diffuse)*color;"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
22
src/main.c
22
src/main.c
@@ -3,6 +3,8 @@
|
|||||||
#include "data/axis.h"
|
#include "data/axis.h"
|
||||||
#include "data/shaders.h"
|
#include "data/shaders.h"
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <cglm/vec3.h>
|
||||||
|
|
||||||
#define WIDTH 512
|
#define WIDTH 512
|
||||||
#define HEIGHT 512
|
#define HEIGHT 512
|
||||||
@@ -27,9 +29,11 @@ void calc_normal(float* v1, float* v2, float* v3, float* normal)
|
|||||||
glm_vec3_normalize(normal);
|
glm_vec3_normalize(normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fill_normal( float * d, float * n )
|
float * fill_normal( float * d )
|
||||||
{
|
{
|
||||||
//*n = *d;
|
float * n;
|
||||||
|
n = malloc( (*d+1)*sizeof(float));
|
||||||
|
*n = *d;
|
||||||
for (int i = 0; i < *d; i += 9)
|
for (int i = 0; i < *d; i += 9)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -39,12 +43,14 @@ void fill_normal( float * d, float * n )
|
|||||||
glm_vec3_copy( norm_vec, (n+1)+i+3 );
|
glm_vec3_copy( norm_vec, (n+1)+i+3 );
|
||||||
glm_vec3_copy( norm_vec, (n+1)+i+6 );
|
glm_vec3_copy( norm_vec, (n+1)+i+6 );
|
||||||
}
|
}
|
||||||
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * wname = "manigraph: manifold grapher";
|
const char * wname = "manigraph: manifold grapher";
|
||||||
|
|
||||||
int main( void )
|
int main( void )
|
||||||
{
|
{
|
||||||
|
float * n_cube, *n_axis;
|
||||||
id_t shader, texture;
|
id_t shader, texture;
|
||||||
mesh_t m_cube, m_axis;
|
mesh_t m_cube, m_axis;
|
||||||
window_t window;
|
window_t window;
|
||||||
@@ -57,8 +63,6 @@ int main( void )
|
|||||||
|
|
||||||
glewInit();
|
glewInit();
|
||||||
|
|
||||||
fill_normal( d_cube, d_cube+(int)*d_cube);
|
|
||||||
|
|
||||||
if( !( shader = create_shader() ) )
|
if( !( shader = create_shader() ) )
|
||||||
goto error_shader;
|
goto error_shader;
|
||||||
|
|
||||||
@@ -68,12 +72,18 @@ int main( void )
|
|||||||
|
|
||||||
load_fix_matrix( shader, (float)WIDTH/HEIGHT );
|
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;
|
goto error_mesh_cube;
|
||||||
|
|
||||||
if( !( m_axis = create_mesh( d_axis ) ) )
|
if( !( m_axis = create_mesh( d_axis, n_axis ) ) )
|
||||||
goto error_mesh_axis;
|
goto error_mesh_axis;
|
||||||
|
|
||||||
|
free( n_cube );
|
||||||
|
free( n_axis );
|
||||||
|
|
||||||
texture=create_palette_texture( palette );
|
texture=create_palette_texture( palette );
|
||||||
use_texture( texture );
|
use_texture( texture );
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ int is_open_window(window_t window);
|
|||||||
|
|
||||||
void close_window(window_t window);
|
void close_window(window_t window);
|
||||||
|
|
||||||
mesh_t create_mesh(narray_float_t mesh);
|
mesh_t create_mesh( float * d, float * n);
|
||||||
|
|
||||||
void destroy_mesh(mesh_t p);
|
void destroy_mesh(mesh_t p);
|
||||||
|
|
||||||
|
|||||||
@@ -13,14 +13,14 @@ mat4 ortho[] =
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
{ 0, 1, 0, 0 },
|
{ 0, 1, 0, 0 },
|
||||||
{ 1, 0, 0, 0 },
|
{-1, 0, 0, 0 },
|
||||||
{ 0, 0, 1, 0 },
|
{ 0, 0, 1, 0 },
|
||||||
{ 0, 0, 0, 1 },
|
{ 0, 0, 0, 1 },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
{ 0, 0, 1, 0 },
|
{ 0, 0, 1, 0 },
|
||||||
{ 0, 1, 0, 0 },
|
{ 0, 1, 0, 0 },
|
||||||
{ 1, 0, 0, 0 },
|
{-1, 0, 0, 0 },
|
||||||
{ 0, 0, 0, 1 },
|
{ 0, 0, 0, 1 },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
28
src/mesh.c
28
src/mesh.c
@@ -4,10 +4,10 @@
|
|||||||
|
|
||||||
struct obj
|
struct obj
|
||||||
{
|
{
|
||||||
unsigned int vertex, n_vao, d_vao, n_vbo, d_vbo;
|
unsigned int vertex, vao, n_vbo, d_vbo;
|
||||||
};
|
};
|
||||||
|
|
||||||
mesh_t create_mesh( narray_float_t d )
|
mesh_t create_mesh( float * d, float * n )
|
||||||
{
|
{
|
||||||
struct obj * p;
|
struct obj * p;
|
||||||
|
|
||||||
@@ -15,24 +15,23 @@ mesh_t create_mesh( narray_float_t d )
|
|||||||
|
|
||||||
p->vertex=(*d)/3;
|
p->vertex=(*d)/3;
|
||||||
|
|
||||||
glGenVertexArrays( 1, &p->n_vao );
|
glGenVertexArrays( 1, &p->vao );
|
||||||
glGenVertexArrays( 1, &p->d_vao );
|
|
||||||
glGenBuffers( 1, &p->d_vbo );
|
glGenBuffers( 1, &p->d_vbo );
|
||||||
glGenBuffers( 1, &p->n_vbo );
|
glBindVertexArray( p->vao );
|
||||||
|
|
||||||
glBindVertexArray( p->d_vao );
|
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, p->d_vbo );
|
glBindBuffer( GL_ARRAY_BUFFER, p->d_vbo );
|
||||||
glBufferData( GL_ARRAY_BUFFER, 2*(p->vertex*3)*sizeof(float), d+1,
|
glBufferData( GL_ARRAY_BUFFER, p->vertex*3*sizeof(float), d+1,
|
||||||
GL_STATIC_DRAW );
|
GL_STATIC_DRAW );
|
||||||
|
|
||||||
glVertexAttribPointer( 0,3,GL_FLOAT, 0, 3*sizeof(float), NULL );
|
glVertexAttribPointer( 0,3,GL_FLOAT, 0, 3*sizeof(float), NULL );
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
|
glGenBuffers( 1, &p->n_vbo );
|
||||||
glVertexAttribPointer( 1,3,GL_FLOAT, *d, 3*sizeof(float), NULL );
|
glBindBuffer( GL_ARRAY_BUFFER, p->n_vbo );
|
||||||
|
glBufferData( GL_ARRAY_BUFFER, p->vertex*3*sizeof(float), n+1,
|
||||||
|
GL_STATIC_DRAW );
|
||||||
|
glVertexAttribPointer( 1,3,GL_FLOAT, 0, 3*sizeof(float), NULL );
|
||||||
glEnableVertexAttribArray(1);
|
glEnableVertexAttribArray(1);
|
||||||
|
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,8 +39,7 @@ void destroy_mesh( mesh_t p )
|
|||||||
{
|
{
|
||||||
struct obj * obj ;
|
struct obj * obj ;
|
||||||
obj = p;
|
obj = p;
|
||||||
glDeleteVertexArrays( 1, &obj->d_vao );
|
glDeleteVertexArrays( 1, &obj->vao );
|
||||||
glDeleteVertexArrays( 1, &obj->n_vao );
|
|
||||||
glDeleteBuffers( 1, &obj->d_vbo );
|
glDeleteBuffers( 1, &obj->d_vbo );
|
||||||
glDeleteBuffers( 1, &obj->n_vbo );
|
glDeleteBuffers( 1, &obj->n_vbo );
|
||||||
free( p );
|
free( p );
|
||||||
@@ -51,7 +49,7 @@ void draw_mesh( mesh_t p )
|
|||||||
{
|
{
|
||||||
struct obj * obj=p;
|
struct obj * obj=p;
|
||||||
|
|
||||||
glBindVertexArray( obj->d_vao );
|
glBindVertexArray( obj->vao );
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|||||||
Reference in New Issue
Block a user