Skip to content

Commit

Permalink
Move shaders to new shaders directory
Browse files Browse the repository at this point in the history
  • Loading branch information
gustafla committed Aug 2, 2023
1 parent 5d39647 commit a6a1500
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 15 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
build/
release/
data/*.track
data/music.ogg
data/
compile_commands.json
.cache/
demo
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand Down
3 changes: 2 additions & 1 deletion scripts/gen_compile_commands_json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)\",
Expand Down
3 changes: 2 additions & 1 deletion scripts/mkfs.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions data/shader.frag → shaders/shader.frag
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions src/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[]){
Expand Down

0 comments on commit a6a1500

Please sign in to comment.