ERROR: 0:10: Invalid call of undeclared identifier 'texture2D'
ERROR: 0:10: Invalid call of undeclared identifier 'texture2D'
我正在使用 Mac 并且在 OpenGL 中,我正在做关于纹理的作业。
当我尝试执行该文件时,我的终端出现空白(黑色)window 并显示以下错误消息:
Compile failure in the fragment shader:
ERROR: 0:10: Invalid call of undeclared identifier 'texture2D'
这是我的片段着色器文件中的代码 06_fshader.glsl
:
#version 330
out vec4 frag_color;
uniform sampler2D texture;
in vec2 tex;
void main ()
{
frag_color = texture2D(texture, tex);
}
我知道这里有类似的问题:GLSL: "Invalid call of undeclared identifier 'texture2D'",但它对我不起作用。
代码有两个问题。第一个是,如链接问题中所述,texture2D
已替换为 texture
。
第二个问题是已经有一个名为 texture
的制服,这会导致在尝试调用 texture
(方法)时发生命名冲突。这可以通过重命名制服来解决。
最终着色器应如下所示:
#version 330
out vec4 frag_color;
uniform sampler2D mytexture;
in vec2 tex;
void main ()
{
frag_color = texture(mytexture, tex);
}
我正在使用 Mac 并且在 OpenGL 中,我正在做关于纹理的作业。
当我尝试执行该文件时,我的终端出现空白(黑色)window 并显示以下错误消息:
Compile failure in the fragment shader:
ERROR: 0:10: Invalid call of undeclared identifier 'texture2D'
这是我的片段着色器文件中的代码 06_fshader.glsl
:
#version 330
out vec4 frag_color;
uniform sampler2D texture;
in vec2 tex;
void main ()
{
frag_color = texture2D(texture, tex);
}
我知道这里有类似的问题:GLSL: "Invalid call of undeclared identifier 'texture2D'",但它对我不起作用。
代码有两个问题。第一个是,如链接问题中所述,texture2D
已替换为 texture
。
第二个问题是已经有一个名为 texture
的制服,这会导致在尝试调用 texture
(方法)时发生命名冲突。这可以通过重命名制服来解决。
最终着色器应如下所示:
#version 330
out vec4 frag_color;
uniform sampler2D mytexture;
in vec2 tex;
void main ()
{
frag_color = texture(mytexture, tex);
}