I’ve seen a lot of examples, tutorials and open-source code that use quotes to assign their shader programs to a const char*. Fully fledged engines would have a way to parse text-files, but if you are doing quick and dirty tests like me, you can use this macro to make editing easier.

Before

const static char* frag_shader_src = \
	"#version 450 core\n"
	"out vec4 frag_color;"
	"void main() {"
		"frag_color = vec4(0.86, 0.62, 0.86, 0.5f);"
	"}\0";

After

#define GLSL(...) #__VA_ARGS__

const static char* frag_shader_src = GLSL(
	#version 450 core\n
	out vec4 frag_color;
	void main() {
		frag_color = vec4(0.86, 0.62, 0.86, 0.5f);
	}\0
);

This uses variadic macros to accept all text between the parenthesis, and wraps it in quotes.

Cover image : [2TC 15] Mystery Mountains by David Hoskins. Winner of twitter long Shadertoy contest. 

Leave a Reply