Hi all,

sometimes you may want to refresh CToy when saving an external file, like a GLSL shader.
Here is a simple trick to do just that thanks to the C (and GLSL) preprocessor.

To force CToy to refresh when an external file is saved, it must be included like a regular C file:
1
2
3
4
#ifdef __TINYC__
#include "../data/my_shader.vert"
#include "../data/my_shader.frag"
#endif

The __TINYC__ macro will make sure this trick is disabled when compiling with another compiler like GCC or VS.

And to make sure the shader will not be compiled by TCC, use the negative of the same macro in the shader:
1
2
3
4
5
6
7
#ifndef __TINYC__
attribute vec4 aPosition;
void main()
{
	gl_Position = aPosition;
}
#endif

Now you can edit the shader files and CToy will refresh on file save.
Cheers !