マクロ文字列化を使用して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 );
}
);
これは、VS2010を使用して正常にビルドおよび実行されますが、次のコマンドでコンパイルできませんgcc
。
error: invalid preprocessing directive #version
このような文字列化をポータブルに使用する方法はありますか?
行ごとの引用符を避けようとしています:
const GLchar* vert =
"#version 120\n"
"attribute vec2 position;"
"void main()"
"{"
" gl_Position = vec4( position, 0.0, 1.0 );"
"}"
;
...および/または行の継続:
const GLchar* vert = "\
#version 120\n \
attribute vec2 position; \
void main() \
{ \
gl_Position = vec4( position, 0.0, 1.0 ); \
} \
";