Macos 要在OS X上编译此OpenGL superbible顶点着色器,我需要做什么?
OpenGL Superbible第五版最近发布,它记录了OpenGL 3.3。不幸的是,OSX只支持OpenGL2.1和GLSL版本1.20。它们提供给您的第一个非平凡顶点着色器无法编译,并显示错误消息:Macos 要在OS X上编译此OpenGL superbible顶点着色器,我需要做什么?,macos,opengl,glsl,Macos,Opengl,Glsl,OpenGL Superbible第五版最近发布,它记录了OpenGL 3.3。不幸的是,OSX只支持OpenGL2.1和GLSL版本1.20。它们提供给您的第一个非平凡顶点着色器无法编译,并显示错误消息: ERROR: 0:5: '' : Version number not supported by GL2 ERROR: 0:8: 'in' : syntax error syntax error 着色器如下所述: // Simple Diffuse lighting Shader //
ERROR: 0:5: '' : Version number not supported by GL2
ERROR: 0:8: 'in' : syntax error syntax error
着色器如下所述:
// Simple Diffuse lighting Shader
// Vertex Shader
// Richard S. Wright Jr.
// OpenGL SuperBible
#version 130
// Incoming per vertex... position and normal
in vec4 vVertex;
in vec3 vNormal;
// Set per batch
uniform vec4 diffuseColor;
uniform vec3 vLightPosition;
uniform mat4 mvpMatrix;
uniform mat4 mvMatrix;
uniform mat3 normalMatrix;
// Color to fragment program
smooth out vec4 vVaryingColor;
void main(void)
{
// Get surface normal in eye coordinates
vec3 vEyeNormal = normalMatrix * vNormal;
// Get vertex position in eye coordinates
vec4 vPosition4 = mvMatrix * vVertex;
vec3 vPosition3 = vPosition4.xyz / vPosition4.w;
// Get vector to light source
vec3 vLightDir = normalize(vLightPosition - vPosition3);
// Dot product gives us diffuse intensity
float diff = max(0.0, dot(vEyeNormal, vLightDir));
// Multiply intensity by diffuse color
vVaryingColor.rgb = diff * diffuseColor.rgb;
vVaryingColor.a = diffuseColor.a;
// Let's not forget to transform the geometry
gl_Position = mvpMatrix * vVertex;
}
除了将版本更改为匹配120之外,还需要将in改为attribute,out改为variable。我可能会错过一些其他的东西,但这就是我现在看到的所有内容。除了将版本更改为匹配120之外,还需要将in改为attribute,out改为variable。我可能会错过一些其他的东西,但这就是我现在所看到的。将glsl版本替换为:
#version 120
但是在1.2中,关键字in和out还没有定义,它是属性的,并且是可变的
smooth varying vec4 vVaryingColor;
您可能需要在片段着色器中进行类似的更改
#version 120
但是在1.2中,关键字in和out还没有定义,它是属性的,并且是可变的
smooth varying vec4 vVaryingColor;
您可能需要在片段着色器中进行类似的更改
谢谢当我回到我的电脑前,我会给这个机会,然后把结果放回堆栈。谢谢!当我回到我的电脑前,我会尝试一下,然后把结果放回堆栈。