diff --git a/Makefile b/Makefile index 86ced9c..89e4d3f 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ OBJ = \ CFLAGS = \ -I./ext/cglm/include \ -I./ext/glfw/include \ - -Wall -Wno-unused-function -std=c99 -D_POSIX_C_SOURCE \ + -Wall -Wno-unused-function -std=c99 -D_GNU_SOURCE \ WAYLAND-LIB = \ xdg-shell \ @@ -48,6 +48,8 @@ windows: $(OBJ) glfw.dll glfw.dll: $(CC) -fPIC -shared -D_GLFW_WIN32 -D_GLFW_BUILD_DLL ./ext/glfw/src/*.c -o $@ -lgdi32 +src/main.o: src/data/shaders.h src/data/axis.h + # LINUX linux-wayland: $(OBJ) for i in $(WAYLAND-LIB); \ @@ -79,4 +81,5 @@ clean: .SUFFIXES: .c .o .c.o: src/main.h + clang-format -i $< $(CC) $(CFLAGS) -c -o $@ $< diff --git a/src/context.c b/src/context.c index e289e38..39c2169 100644 --- a/src/context.c +++ b/src/context.c @@ -1,7 +1,7 @@ #include "main.h" #ifdef GLAD -#include #include +#include #else #include #endif @@ -19,9 +19,8 @@ int init_context(void) return gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); #else - return glewInit() == GLEW_OK; + return glewInit(); #endif - } void clean_context(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } diff --git a/src/data/shaders.h b/src/data/shaders.h index 03cdc2c..1f058ce 100644 --- a/src/data/shaders.h +++ b/src/data/shaders.h @@ -46,27 +46,32 @@ const char * fs_plain = " FragColor = texture( palette, vec3( 0, 0, index ) ).rgba;" "}"; - const char * fs = - "#version 330 core\n" + "#version 330 core\n" - "uniform sampler2DArray palette;" + "uniform sampler2DArray palette;" - "in float index;" - "out vec4 FragColor;" - "in vec3 Normal;" - "in vec3 FragPos;" + "in float index;" + "in vec3 Normal;" + "in vec3 FragPos;" - "void main()" - "{" + "out vec4 FragColor;" - " vec4 color = texture( palette, vec3( 0, 0, index ) ).rgba;" - " vec3 lightPos = vec3(0,0,-15);" - " vec3 lightDir = normalize(lightPos - FragPos);" + "void main()" + "{" + " vec4 color = texture(palette, vec3(0, 0, index));\n" - " float diffuse = abs(dot(Normal, lightDir)); " + " vec3 viewPos = vec3(0, 0, -15);\n" + " vec3 viewDir = normalize(viewPos - FragPos);\n" - " FragColor = (0.5 + 0.5*diffuse)*color;" - "}"; + " vec3 lightPos = viewPos;\n" + " vec3 lightDir = normalize(lightPos - FragPos);\n" - + " vec3 halfwayDir = normalize(lightDir + viewDir);\n" + + " float specular = pow(max(dot(normalize(Normal), halfwayDir), 0.0), 16.0);\n" + " float diffuse = max(dot(normalize(Normal), lightDir), 0.0);\n" + + " vec3 result = (0.5 + 0.5 * diffuse + specular) * color.rgb;\n" + " FragColor = vec4(result, color.a);\n" + "}"; diff --git a/src/main.c b/src/main.c old mode 100644 new mode 100755 diff --git a/src/mesh.c b/src/mesh.c index a19931e..100be67 100644 --- a/src/mesh.c +++ b/src/mesh.c @@ -68,8 +68,8 @@ mesh_t create_mesh(float *d, float *n, unsigned char m) { glGenBuffers(1, &p->n_vbo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, p->n_vbo); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, p->vertex * m * sizeof(float), n + 1, - GL_STATIC_DRAW); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, p->vertex * m * sizeof(float), + n + 1, GL_STATIC_DRAW); } for (i = 0; i < 4; ++i)