我想使用宏字符串化声明内联的GLSL着色器字符串:
#define STRINGIFY(A) #A
const GLchar* vert = STRINGIFY(
#version 120\n
attribute vec2 position;
void main()
{
gl_Position = vec4( position, 0.0, 1.0 );
}
);
Run Code Online (Sandbox Code Playgroud)
这使用VS2010构建并运行良好,但无法编译gcc:
error: invalid preprocessing directive #version
Run Code Online (Sandbox Code Playgroud)
有没有办法以可移植的方式使用这样的字符串化?
我试图避免每行引用:
const GLchar* vert =
"#version 120\n"
"attribute vec2 position;"
"void main()"
"{"
" gl_Position = vec4( position, 0.0, 1.0 );"
"}"
;
Run Code Online (Sandbox Code Playgroud)
......和/或续行:
const GLchar* vert = "\
#version 120\n \
attribute vec2 position; \
void main() \
{ \
gl_Position = vec4( position, …Run Code Online (Sandbox Code Playgroud)