2010-08-23 17 views
1

最近发布了OpenGL Superbible 5th Edition,它记录了OpenGL 3.3。不幸的是,OS X只支持OpenGL 2.1和GLSL 1.20版本。他们给你的第一个不平凡的顶点着色器失败,出现错误消息编译:我需要做什么才能让这个OpenGL超炫的顶点着色器在OS X上编译?

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; 
    } 

回答

0

更新2011:从OS X Lion开始,这不再是这种情况。 Lion已经增加了对OpenGL 3.2的支持。

不幸的是,我已经认为这是一个傻瓜的差事。本书使用了一个GLTools库(分布在网站上),它以与OpenGL 2.1基本不兼容的方式强制传入各种参数。

如果它是一个例子,它可以被重写,但是它是一些例子,如果你试图自学OpenGL,那么返回的努力将是压倒性的。

你有两个选择:

  1. 购买Windows机器,支持OpenGL 3,把你的Mac在角落里,直到苹果台阶,以支持新的标准。
  2. 购买仍在印刷中的第4版本书。

website

如果你仍然有兴趣在OpenGL预3.X的否决的功能,我们建议第四版,这仍然是在打印,以及覆盖的OpenGL 2.1和固定功能流水线相当彻底。

1

改变#version的短匹配120,你还需要将in更改为attributeoutvarying。我可能会错过其他的东西,但这就是我现在所看到的。

4

通过更换GLSL版本:

#version 120 

但在1.2和移出均尚未定义关键字,这是属性和不同的。

smooth varying vec4 vVaryingColor; 

你可能需要在片段着色器

对于vVertex和vNormal类似的变化,这些都是自定义名称,这意味着他们在C++代码绑定。解决此问题的最简单方法是将它们重命名为gl_Vertex和gl_Normal

+0

谢谢!当我回到我的电脑时,我会给这个镜头一个镜头,然后回头看看结果。 – 2010-08-23 17:07:51

相关问题