我想使用宏字符串化内联声明 GLSL 着色器字符串:
I'd like to declare GLSL shader strings inline using macro stringification:
#define STRINGIFY(A) #A
const GLchar* vert = STRINGIFY(
#version 120
attribute vec2 position;
void main()
{
gl_Position = vec4( position, 0.0, 1.0 );
}
);
使用 VS2010 构建并运行良好,但无法在 gcc 上编译:
This builds and runs fine using VS2010 but fails to compile on gcc with:
error: invalid preprocessing directive #version
有没有办法以可移植的方式使用这样的字符串化?
Is there a way to use stringification like this in a portable manner?
我试图避免每行引号:
const GLchar* vert =
"#version 120
"
"attribute vec2 position;"
"void main()"
"{"
" gl_Position = vec4( position, 0.0, 1.0 );"
"}"
;
...和/或续行:
const GLchar* vert = "
#version 120
attribute vec2 position;
void main()
{
gl_Position = vec4( position, 0.0, 1.0 );
}
";
你会使用 C++11 吗?如果是这样,您可以使用 原始字符串文字:
Can you use C++11? If so you could use raw string literals:
const GLchar* vert = R"END(
#version 120
attribute vec2 position;
void main()
{
gl_Position = vec4( position, 0.0, 1.0 );
}
)END";
无需转义或显式换行.这些字符串以 R(或 r)开头.您需要在引号和第一个括号之间使用分隔符(我选择了 END)来转义代码片段中的括号.
No need for escapes or explicit newlines. These strings start with an R (or r). You need a delimiter (I chose END) between the quote and the first parenthesis to escape parenthesis which you have in the code snippet.
这篇关于GCC、字符串化和内联 GLSL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
fpermissive 标志有什么作用?What does the fpermissive flag do?(fpermissive 标志有什么作用?)
如何在我不想编辑的第 3 方代码中禁用来自 gccHow do you disable the unused variable warnings coming out of gcc in 3rd party code I do not wish to edit?(如何在我不想编辑的第 3 方代码中禁
使用 GCC 预编译头文件Precompiled headers with GCC(使用 GCC 预编译头文件)
如何在 OS X 中包含 omp.h?How to include omp.h in OS X?(如何在 OS X 中包含 omp.h?)
如何让 GCC 将 .text 部分编译为可写在 ELF 二进制文How can I make GCC compile the .text section as writable in an ELF binary?(如何让 GCC 将 .text 部分编译为可写在 ELF 二进制文件中?)
从 char** 到 const char** 的隐式转换Implicit conversion from char** to const char**(从 char** 到 const char** 的隐式转换)