【问题标题】:GLSL : Use of undeclared identifier 'gl_FragData'GLSL:使用未声明的标识符“gl_FragData”
【发布时间】:2015-10-20 16:20:11
【问题描述】:

我正在调试一个非常大的项目,对树进行着色,在该项目中作者使用 glsl 文件对树进行着色,但我在编译 glsl 文件时遇到了问题:

这是错误日志:

compile: code/trees/TreeRender/Shader/Graph40.vert.glsl
    ERROR: 0:4: '' : syntax error: #version
    ERROR: 0:15: 'layout' : syntax error: syntax error

Graph40.vert.glsl:

 #version 120 core  //the original file use version 400

#define VERT_POSITION   0
#define VERT_NORMAL     1
#define VERT_COLOR      2
#define VERT_TEXTURE    3

uniform mat4x4 matModel;
uniform mat4x4 matView;
uniform mat4x4 matProjection;

layout(location = VERT_POSITION) in vec4 Position;
layout(location = VERT_NORMAL)   in vec4 Normal;
layout(location = VERT_COLOR)    in vec4 Color;
layout(location = VERT_TEXTURE)  in vec4 Texture;

out vec4 VertPosition;
out vec4 VertNormal;
out vec4 VertColor;
out vec4 VertTexture;

void main()
{      
    VertPosition = Position; 
    VertNormal   = Normal;
    VertColor    = Color;
    VertTexture  = Texture;

    gl_Position = matProjection * matView * matModel * vec4(Position.xyz, 1);
}

另一个错误日志:

compile: code/trees/TreeRender/Shader/Default.vert.glsl
ERROR: 0:11: 'matModel' : syntax error: syntax error

Default.vert.glsl:

#define VERT_POSITION   0
#define VERT_NORMAL     1
#define VERT_COLOR      2
#define VERT_TEXTURE    3

uniform mat4x4 matModel;
uniform mat4x4 matView;
uniform mat4x4 matProjection;

layout(location = VERT_POSITION) in vec4 Position;
layout(location = VERT_NORMAL)   in vec4 Normal;
layout(location = VERT_COLOR)    in vec4 Color;
layout(location = VERT_TEXTURE)  in vec4 Texture;

out vec4 VertPosition;
out vec4 VertNormal;
out vec4 VertColor;
out vec4 VertTexture;

void main()
{      
    VertPosition = Position; 
    VertNormal   = Normal;
    VertColor    = Color;
    VertTexture  = Texture;

    gl_Position = matProjection * matView * matModel * vec4(Position.xyz, 1);
}

我尝试用谷歌搜索错误,但没有找到可行的解决方案。

我使用mac osx,xcode 7.0,OpenGL和glut都是默认版本。 Glew 版本是 1.13.0。

是因为版本与作者使用的原始版本不匹配吗?因为我查了原版,他用的是GLEW 1.9.0和GLUT 3.7.6。

/////更新//////

原来的 glsl 文件有:

#version 400 core 

但是会有错误:

ERROR: 0:4: '' :  version '400' is not supported
ERROR: 0:4: '' : syntax error: #version

所以我评论了那行。但其他错误仍然存​​在。

我检查了我的 OpenGL 版本,使用 OpenGL 扩展查看器,它在我的 mac 中是 4.1,但比它更旧的版本也受支持并且应该也可以工作。但是当我换成#version 410核心时,还是一样的错误,说不支持410。

//////////更新///////////

原来 mac 支持的版本不是我的上下文使用的版本。我使用 GL_VERSION 在我的代码中打印,我使用的是 2.1。根据[this][1],现在我已更改为4.1。但是还是有错误:

trees/TreeRender/Shader/DefaultDepth.frag.glsl
helloERROR: 0:20: Use of undeclared identifier 'gl_FragData'

DefaultLight.frag.glsl:

#version 400 core


in vec4 VertPosition;
in vec4 VertNormal;
in vec4 VertColor;
in vec4 VertTexture;

uniform vec3 lightPos;

void main()
{
    float moment1 = gl_FragCoord.z;
    float moment2 = moment1 * moment1;

    gl_FragData[0] = vec4(moment1, moment2, 0.0, 1.0);

}

【问题讨论】:

  • #version 120 肯定没有core 个人资料。如果你想使用corelayout,你至少需要#version 150
  • @genpfault 很抱歉我刚刚更改了它,我有使用#version 400 核心的原始文件,但仍然存在此错误。现在我已经注释了每个 glsl 文件中的所有#version 语句,因此错误消失了,但“布局”错误和“matModel”错误仍然存​​在。但是我觉得写得还不错,应该不会导致这些错误,一定是版本或者配置有问题……
  • 没有#version 指令意味着#version 110 也不支持corelayout。可以试试#version 150 core。还要确保您从操作系统请求核心上下文。
  • 你的上下文有哪个 OpenGL 版本?
  • @BDL 非常感谢!我在上下文中打印了版本,我使用的是 2.1。现在已经升级到4.1了,但是还是报错“Use of undeclared identifier 'gl_FragColor'”,这次应该不是版本问题吧?

标签: macos qt opengl glsl


【解决方案1】:

版本 120 不支持核心配置文件(仅限 OpenGL 3.2+) 布局限定符也仅在 OpenGL 3.2+ 中可用

【讨论】:

猜你喜欢
  • 2014-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多