From ee1d1eb500349423599c3a317d97dd5fe0d75580 Mon Sep 17 00:00:00 2001 From: Fabrice Date: Thu, 12 Feb 2026 16:36:56 +0100 Subject: working on compiling shaders --- Makefile | 14 +++++++++++++- assets/text.glsl | 38 ++++++++++++++++++++++++++++++++++++++ src/text.h | 11 +++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/text.h diff --git a/Makefile b/Makefile index d935225..f82baf6 100644 --- a/Makefile +++ b/Makefile @@ -64,13 +64,20 @@ SOKOL_DIR = $(WORK_DIR)/sokol SOKOL_BIN = $(WORK_DIR)/sokol_bin/bin SOKOL_SHDC = $(SOKOL_BIN)/$(PLATFORM)/sokol-shdc +ASSETS_DIR = $(WORK_DIR)/assets +SHADERS = \ + $(ASSETS_DIR)/text.glsl + +SHADER_HEADERS = $(SHADERS:.glsl=.h) + CSH_FLAGS += \ -I$(MI_INCLUDE) \ -I$(HASHMAP_DIR) \ -I$(GLAD_DIR) \ -I$(CGLM_INCLUDE) \ -I$(FREETYPE_INCLUDE) \ - -I$(SOKOL_DIR) + -I$(SOKOL_DIR) \ + -I$(ASSETS_DIR) CMAKE_GENERATOR = "Unix Makefiles" @@ -125,11 +132,16 @@ $(WAYCLOCK): $(OBJECTS) $(LIBRARIES) @echo " CC $<" @$(CC) $(CC_FLAGS) -c -o $@ $< +%.h: %.glsl + @echo " SHDC $<" + @$(SOKOL_SHDC) --slang=glsl430 --format=sokol --input=$< --output=$@ + .PHONY: clean clean: @$(RM) $(MI_BUILD) @$(RM) $(FREETYPE_BUILD) @$(RM) $(WAYCLOCK) @$(RM) $(OBJECTS) $(DEPS) + @$(RM) $(SHADER_HEADERS) -include $(DEPS) \ No newline at end of file diff --git a/assets/text.glsl b/assets/text.glsl index e69de29..3b6ed18 100644 --- a/assets/text.glsl +++ b/assets/text.glsl @@ -0,0 +1,38 @@ +@header #include "cglm/cglm.h" + +@vs vs_text +in vec2 in_position; +in vec2 in_uv; + +layout(binding = 0) uniform vs_text_params { + mat4 mvp; + vec4 color; +} + +out vec2 out_uv; +out vec4 out_color; + +void main() { + gl_Position = mvp * vec4(in_position, 0.0, 1.0); + out_uv = in_uv; + out_color = color; +} + +@end + +@fs fs_text +layout(binding = 0) uniform texture2D u_texture; +layout(binding = 1) uniform sampler u_sampler; + +in vec2 in_uv; +in vec4 in_color; + +out vec4 out_color; + +void main() { + float alpha = texture(sampler2D(u_texture, u_sampler), in_uv).r; + out_color = vec4(in_color.rgb, in_color.a * alpha); +} + +@end +@program text vs_text fs_text \ No newline at end of file diff --git a/src/text.h b/src/text.h new file mode 100644 index 0000000..6eb7df1 --- /dev/null +++ b/src/text.h @@ -0,0 +1,11 @@ +#pragma once + +#include "freetype/freetype.h" + +struct face_ctx_s { + FT_Library library; +}; + +struct face_s { + FT_Face face; +}; \ No newline at end of file -- cgit v1.2.3