使用未声明的标识符"gl_LightSource"
Use of undeclared identifier 'gl_LightSource'
这真的很奇怪:
以下是一些日志:
OpenGL Version = 4.1 INTEL-10.2.40
vs shaderid = 1, file = shaders/pointlight_shadow.vert
- Shader 1 (shaders/pointlight_shadow.vert) compile error: ERROR: 0:39: Use of undeclared identifier 'gl_LightSource'
顺便说一句,我在Mac OS X 10.10上使用C++/OpenGL/GLFW/GLEW。有没有办法检查在着色器语言中使用"gl_LightSource"所需的所有版本或属性?
着色器文件:
#version 330
// Input vertex data, different for all executions of this shader.
layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec2 vertexUV;
layout(location = 2) in vec3 vertexNormal_modelspace;
layout(location = 3) in vec3 vertexTangent_modelspace;
layout(location = 4) in vec3 vertexBitangent_modelspace;
out vec4 diffuse,ambientGlobal, ambient;
out vec3 normal,lightDir,halfVector;
out float dist;
out vec3 fragmentcolor;
out vec4 ShadowCoord;
//Model, view, projection matrices
uniform mat4 MVP;
uniform mat4 V;
uniform mat4 M;
uniform mat3 MV3x3;
uniform mat4 DepthBiasMVP;
void main()
{
//shadow coordinate in light space...
ShadowCoord = DepthBiasMVP * vec4(vertexPosition_modelspace,1);
// first transform the normal into camera space and normalize the result
normal = normalize(MV3x3 * vertexNormal_modelspace);
// now normalize the light's direction. Note that according to the
// OpenGL specification, the light is stored in eye space.
gl_Position = MVP * vec4(vertexPosition_modelspace,1);
vec3 vertexPosition_worldspace = (M * vec4(vertexPosition_modelspace,1)).xyz;
vec3 vertexPosition_cameraspace = ( V * M * vec4(vertexPosition_modelspace,1)).xyz;
//light
vec3 light0_camerapace = (V* vec4(gl_LightSource[0].position.xyz,1) ).xyz;
vec3 L_cameraspace= light0_camerapace-vertexPosition_cameraspace;
lightDir = normalize(L_cameraspace);
// compute the distance to the light source to a varying variable
dist = length(L_cameraspace);
// Normalize the halfVector to pass it to the fragment shader
{
// compute eye vector and normalize it
vec3 eye = normalize(-vertexPosition_cameraspace);
// compute the half vector
halfVector = normalize(lightDir + eye);
}
// Compute the diffuse, ambient and globalAmbient terms
diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
ambientGlobal = gl_LightModel.ambient * gl_FrontMaterial.ambient;
}
您没有在着色器版本中指定配置文件:
#version 330
在这种情况下,默认值为 core
,对应于 OpenGL 核心配置文件。在某些平台上,您可以将其更改为使用兼容性配置文件:
#version 330 compatibility
但是既然你说你正在Mac OS上工作,那对你来说不是一个选择。Mac OS 仅支持 OpenGL 3.x 及更高版本的核心配置文件。
着色器不使用核心配置文件进行编译的原因是,您使用的是一堆已弃用的预定义变量。例如:
gl_FrontMaterial
gl_LightSource
gl_LightModel
所有这些都与旧式固定函数管道一起使用,该管道在核心配置文件中不再可用。您必须为这些值定义自己的统一变量,并通过glUniform*()
调用将这些值传递到着色器中。
我在这里的答案中写了关于内置 GLSL 变量在过渡到核心配置文件时发生了什么的更详细的描述:GLSL - 使用自定义输出属性而不是gl_Position。
相关文章:
- Visual Studio 19-17 库兼容性根据 GL 标志
- glDrawElements GL 错误类型 = 0x824c,严重性 = 0x9146,消息 = GL_INVALID
- 将"Compass"与相机旋转隔离开GL
- 是否有一个版本的glCopyImageSubData在Openg GL中使用混合?
- 计算着色器Open GL ES的多个输入
- Open GL ES 3.1 的计算着色器的最小工作示例
- 致命错误 C1083:无法打开包含文件:"GL/glew.h":没有此类文件或目录
- C++ 致命错误:glad/gl.h:没有这样的文件或目录
- 打开 gl 精灵类不起作用
- Qt 找不到 GL 库
- GCC 相当于 MSVC 中的 /GS、/GL、/Gy、/Oi、/MD
- 失败的 glewInit:缺少 GL 版本
- 何时在OS X上使用OpenGL vs GL
- 识别安卓中意外的 GL 上下文丢失
- Android Native:CMake 链接错误:未定义对 GL 函数的引用 - 即使包含并链接了 EGL 和 GLESv3
- Glew - 与 GLFW 配对时 gl- 函数符号上出现链接错误
- 打开gl es 2.0为什么我的VBO不起作用
- iOS GL ES exc_bad_access on glDrawElements
- "Missing GL version" 从 glewInit() 使用 EGL?
- 在CentOS 7上从源代码构建TileServer GL