相关疑难解决方法(0)

GCC,字符串化和内联GLSL?

我想使用宏字符串化声明内联的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)

c++ opengl gcc glsl c-preprocessor

18
推荐指数
4
解决办法
6941
查看次数

标签 统计

c++ ×1

c-preprocessor ×1

gcc ×1

glsl ×1

opengl ×1