diff --git a/.gitignore b/.gitignore index 9fc8bba..1ba29d4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ build/ release/ -data/*.track -data/music.ogg +data/ compile_commands.json .cache/ demo diff --git a/Makefile b/Makefile index 1f569e4..60034a8 100644 --- a/Makefile +++ b/Makefile @@ -78,16 +78,16 @@ $(BUILDDIR)/include/stb_vorbis.c: lib/stb/stb_vorbis.c # This rule is for generating build/include/data.c -$(BUILDDIR)/include/data.c: $(wildcard data/*) +$(BUILDDIR)/include/data.c: $(wildcard shaders/*) $(wildcard data/*) @mkdir -p $(BUILDDIR)/include - scripts/mkfs.sh > $@ + scripts/mkfs.sh shaders/ data/ > $@ # This generates a compile_commands.json file for clangd, clang-tidy etc. devtools compile_commands.json: $(SOURCES) - CC=$(CC) CFLAGS="$(CFLAGS) $(EXTRA_CFLAGS)" scripts/gen_compile_commands_json.sh > $@ + CC=$(CC) CFLAGS="$(CFLAGS) $(EXTRA_CFLAGS)" scripts/gen_compile_commands_json.sh $(SOURCEDIR) > $@ + - .PHONY: clean diff --git a/README.md b/README.md index 43d5690..2f30ef8 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,12 @@ Welcome. This is a C99 codebase which will let you get started with creating native OpenGL demos on Linux. The repository is structured so that -[`data/`](data/) contains binary files (assets such as music) as well as shaders, -[`src/`](src/) contains source code, [`scripts/`](scripts/) contains scripts -that are required for building the demo and [`lib/`](lib/) contains third-party -libraries (git submodules). +[`data/`](data/) contains binary files (assets such as music), +[`shaders/`](shaders/) contains shaders, +[`src/`](src/) contains source code, +[`scripts/`](scripts/) contains scripts +that are required for building the demo and +[`lib/`](lib/) contains third-party libraries (git submodules). The result is an executable which shows some GLSL shaders with music, sync and post processing, and won't depend on any other files. @@ -56,7 +58,7 @@ This will use all CPU cores you have available. 1. Edit [`src/config.h`](src/config.h) to match your desired resolution and **your music track's BPM**! Don't skip this. Then run `make` once more. 2. Open your [rocket](https://rocket.github.io/) editor. I prefer the default Qt-based rocket editor. 3. Start `./build/demo` -4. Open `data/shader.frag` in your editor. +4. Open `shaders/shader.frag` in your editor. 5. Hack on shaders! Uniforms prefixed with `r_` will automatically show up in rocket. 6. Reload shaders and uniforms by pressing R. No `make` or restart needed. diff --git a/scripts/gen_compile_commands_json.sh b/scripts/gen_compile_commands_json.sh index 4c8ef4e..95a3495 100755 --- a/scripts/gen_compile_commands_json.sh +++ b/scripts/gen_compile_commands_json.sh @@ -2,9 +2,10 @@ set -e [ -z "$CC" ] && echo Set CC && exit 1 [ -z "$CFLAGS" ] && echo Set CFLAGS && exit 1 +[ -z "$1" ] && echo Pass source directory as argument && exit 1 echo '[' -for file in src/*.c; do +for file in "$1"/*.c; do echo ' {' echo ' "arguments": [' echo ' '\"$(which $CC)\", diff --git a/scripts/mkfs.sh b/scripts/mkfs.sh index 32941a9..2217502 100755 --- a/scripts/mkfs.sh +++ b/scripts/mkfs.sh @@ -1,7 +1,8 @@ #!/bin/sh set -e +[ -z "$1" ] && echo Pass input directories as arguments && exit 1 -IN=data/* +IN=$(find $@ -type f) # Convert every data file to C source with xxd for file in $IN; do diff --git a/data/post.frag b/shaders/post.frag similarity index 100% rename from data/post.frag rename to shaders/post.frag diff --git a/data/shader.frag b/shaders/shader.frag similarity index 86% rename from data/shader.frag rename to shaders/shader.frag index 8d79274..55181e9 100644 --- a/data/shader.frag +++ b/shaders/shader.frag @@ -10,4 +10,5 @@ uniform vec3 r_CamPos; void main() { FragColor = vec4(TexCoord, sin(u_RocketRow * 6.283 / 8.) * r_TestValue, 1.); + FragColor += vec4(0, 1, 1, 0); } diff --git a/src/demo.c b/src/demo.c index e83a915..56e8687 100644 --- a/src/demo.c +++ b/src/demo.c @@ -92,13 +92,13 @@ static void replace_program(program_t *old, program_t new) { void demo_reload(demo_t *demo) { shader_t vertex_shader = compile_shader(vertex_shader_src, "vert"); - shader_t fragment_shader = compile_shader_file("data/shader.frag"); + shader_t fragment_shader = compile_shader_file("shaders/shader.frag"); replace_program( &demo->effect_program, link_program((shader_t[]){vertex_shader, fragment_shader}, 2)); - shader_t post_shader = compile_shader_file("data/post.frag"); + shader_t post_shader = compile_shader_file("shaders/post.frag"); replace_program(&demo->post_program, link_program( (shader_t[]){