From 1e009d5bdfe6ac2f11ee4358739d030bfa9a308c Mon Sep 17 00:00:00 2001 From: PedroEdiaz Date: Thu, 28 Nov 2024 09:55:48 -0600 Subject: [PATCH] Fix gamma, add Glad, error if glad is compiled with emscripten --- Makefile | 2 ++ src/context.c | 3 +-- src/data/shaders.h | 7 ++++--- src/main.c | 8 +++++--- src/main.h | 8 +++++++- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index b2e71e1..28b3e45 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ BIN = manigraph OBJ = \ + ext/glad/glad.o \ src/surface.o \ src/context.o \ src/texture.o \ @@ -14,6 +15,7 @@ OBJ = \ CFLAGS = \ -I./ext/cglm/include \ -I./ext/glfw/include \ + -I./ext/glad \ -Wall -Wno-unused-function -std=c99 -D_GNU_SOURCE \ WAYLAND-LIB = \ diff --git a/src/context.c b/src/context.c index 4eb36bb..be286b5 100644 --- a/src/context.c +++ b/src/context.c @@ -4,8 +4,8 @@ #include #else #ifdef GLAD -#include #include +#include #else #include #endif @@ -14,7 +14,6 @@ void set_clean_color_context(unsigned char r, unsigned char g, unsigned char b) { glEnable(GL_DEPTH_TEST); - glEnable(GL_FRAMEBUFFER_SRGB); glClearColor((float)r / 0xff, (float)g / 0xff, (float)b / 0xff, 1.0); } diff --git a/src/data/shaders.h b/src/data/shaders.h index 48294f5..0e17dc0 100644 --- a/src/data/shaders.h +++ b/src/data/shaders.h @@ -67,7 +67,8 @@ const char * fs_plain = "void main()" "{" - " FragColor = texture( palette, vec3( 0, 0, index ) ).rgba;" + " vec4 color = texture( palette, vec3(0,0,index)).rgba;" + " FragColor = vec4(pow(vec3(color),vec3(1.0/2.2)),color.a);" "}"; const char * fs = @@ -102,6 +103,6 @@ const char * fs = " float specular = pow(abs(dot(normalize(Normal), halfwayDir)), 32.0);\n" " float diffuse = abs(dot(normalize(Normal), lightDir));\n" - " vec3 result = (0.5 + 1.5*diffuse + 4*specular) * color.rgb;\n" - " FragColor = vec4(result, color.a)*1/2.2;\n" + " vec3 result = pow((0.5 + 0.5*diffuse + 1.5*specular) * color.rgb, vec3(1.0/2.2));\n" + " FragColor = vec4(result, color.a);\n" "}"; diff --git a/src/main.c b/src/main.c index fd7ae8d..7a84d89 100644 --- a/src/main.c +++ b/src/main.c @@ -19,7 +19,7 @@ float *generate_data_surface(unsigned int, unsigned char *); float *generate_normals_surface(float *, unsigned char); -struct projection projection = {.x = 3, .y=1, .z=2, .w=0 }; +struct projection projection = {.x = 0, .y=1, .z=2, .w=3 }; const char *wname = "manigraph: manifold grapher"; @@ -65,6 +65,7 @@ void main_loop(void) load_uint_to_shader( shader, "i", animate_index-1 ); load_uint_to_shader( shader_plain, "i", animate_index-1 ); + load_float_to_shader( shader, "angle", angle); load_float_to_shader( shader_plain, "angle", angle); } @@ -117,7 +118,7 @@ int main(void) mlog("[CONTEXT] Error al inicializar...\n"); goto error_context; } - set_clean_color_context(0xFB, 0xEA, 0xEB); + set_clean_color_context(0xFF, 0xFF, 0xFF); } mlog("[TEXTURE] Inicializando...\n"); @@ -184,7 +185,8 @@ int main(void) mlog("[MAIN LOOP] Inicializando...\n"); #ifdef EMSCRIPTEN - emscripten_set_main_loop(&main_loop, 0, 1); + emscripten_set_main_loop(&main_loop, 60, 1); + return 0; #else while (is_open_window(window)) main_loop(); diff --git a/src/main.h b/src/main.h index c003e36..9fb0637 100644 --- a/src/main.h +++ b/src/main.h @@ -5,7 +5,7 @@ */ /* #define DEBUG */ -/* #define GLAD */ +#define GLAD typedef const void * window_t; typedef unsigned int id_t; @@ -154,3 +154,9 @@ void destroy_texture(id_t texture); id_t create_palette_texture(const unsigned char colors[][4], unsigned char n ); quat_t poll_input(window_t window); + +#ifdef EMSCRIPTEN +#ifdef GLAD +#error undefine GLAD on src/main.h please +#endif +#endif