Merge: roberto -> main

This commit is contained in:
PedroEdiaz
2024-11-16 13:12:16 -06:00
5 changed files with 29 additions and 22 deletions

View File

@@ -14,7 +14,7 @@ OBJ = \
CFLAGS = \ CFLAGS = \
-I./ext/cglm/include \ -I./ext/cglm/include \
-I./ext/glfw/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 = \ WAYLAND-LIB = \
xdg-shell \ xdg-shell \
@@ -48,6 +48,8 @@ windows: $(OBJ) glfw.dll
glfw.dll: glfw.dll:
$(CC) -fPIC -shared -D_GLFW_WIN32 -D_GLFW_BUILD_DLL ./ext/glfw/src/*.c -o $@ -lgdi32 $(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
linux-wayland: $(OBJ) linux-wayland: $(OBJ)
for i in $(WAYLAND-LIB); \ for i in $(WAYLAND-LIB); \
@@ -79,4 +81,5 @@ clean:
.SUFFIXES: .c .o .SUFFIXES: .c .o
.c.o: src/main.h .c.o: src/main.h
clang-format -i $<
$(CC) $(CFLAGS) -c -o $@ $< $(CC) $(CFLAGS) -c -o $@ $<

View File

@@ -1,7 +1,7 @@
#include "main.h" #include "main.h"
#ifdef GLAD #ifdef GLAD
#include <glad.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <glad.h>
#else #else
#include <GL/glew.h> #include <GL/glew.h>
#endif #endif
@@ -19,9 +19,8 @@ int init_context(void)
return gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); return gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
#else #else
return glewInit() == GLEW_OK; return glewInit();
#endif #endif
} }
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

@@ -46,27 +46,32 @@ const char * fs_plain =
" FragColor = texture( palette, vec3( 0, 0, index ) ).rgba;" " FragColor = texture( palette, vec3( 0, 0, index ) ).rgba;"
"}"; "}";
const char * fs = const char * fs =
"#version 330 core\n" "#version 330 core\n"
"uniform sampler2DArray palette;" "uniform sampler2DArray palette;"
"in float index;" "in float index;"
"out vec4 FragColor;" "in vec3 Normal;"
"in vec3 Normal;" "in vec3 FragPos;"
"in vec3 FragPos;"
"void main()" "out vec4 FragColor;"
"{"
" vec4 color = texture( palette, vec3( 0, 0, index ) ).rgba;" "void main()"
" vec3 lightPos = vec3(0,0,-15);" "{"
" vec3 lightDir = normalize(lightPos - FragPos);" " 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"
"}";

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

View File

@@ -68,8 +68,8 @@ mesh_t create_mesh(float *d, float *n, unsigned char m)
{ {
glGenBuffers(1, &p->n_vbo); glGenBuffers(1, &p->n_vbo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, p->n_vbo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, p->n_vbo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, p->vertex * m * sizeof(float), n + 1, glBufferData(GL_ELEMENT_ARRAY_BUFFER, p->vertex * m * sizeof(float),
GL_STATIC_DRAW); n + 1, GL_STATIC_DRAW);
} }
for (i = 0; i < 4; ++i) for (i = 0; i < 4; ++i)