Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用未声明的标识符“gl_光源”_C++_Opengl_Glsl_Shader - Fatal编程技术网

C++ 使用未声明的标识符“gl_光源”

C++ 使用未声明的标识符“gl_光源”,c++,opengl,glsl,shader,C++,Opengl,Glsl,Shader,真奇怪: 以下是一些日志: 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' 顺便说一句,我在MacOSX10.10上使用C++/O

真奇怪:

以下是一些日志:

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'
顺便说一句,我在MacOSX10.10上使用C++/OpenGL/GLFW/GLEW。是否有方法检查在着色器语言中使用gl_光源所需的所有版本或属性

着色器文件:

#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 core概要文件。在某些平台上,您可以将此更改为使用兼容性配置文件:

#version 330 compatibility
但既然你说你在使用Mac OS,那就不是你的选择。Mac OS仅支持OpenGL 3.x及更高版本的核心配置文件

着色器不使用核心配置文件编译的原因是使用了大量不推荐使用的预定义变量。例如:

gl_FrontMaterial
gl_LightSource
gl_LightModel
所有这些都与旧式的固定功能管道一起使用,这在核心概要文件中不再可用。您必须为这些值定义自己的统一变量,并使用glUniform*调用将这些值传递到着色器中


我在这里的回答中更详细地描述了在转换到核心配置文件时内置GLSL变量发生的情况:。

您没有在着色器版本中指定配置文件:

#version 330
本例中的默认值是core,对应于OpenGL core概要文件。在某些平台上,您可以将此更改为使用兼容性配置文件:

#version 330 compatibility
但既然你说你在使用Mac OS,那就不是你的选择。Mac OS仅支持OpenGL 3.x及更高版本的核心配置文件

着色器不使用核心配置文件编译的原因是使用了大量不推荐使用的预定义变量。例如:

gl_FrontMaterial
gl_LightSource
gl_LightModel
所有这些都与旧式的固定功能管道一起使用,这在核心概要文件中不再可用。您必须为这些值定义自己的统一变量,并使用glUniform*调用将这些值传递到着色器中

我在这里的一个回答中更详细地描述了在转换到核心概要文件时内置GLSL变量发生了什么:。

是否遗漏了include语句?是否遗漏了include语句?