2014-08-29 127 views
0

我发现this vertex shaderX射线顶点着色器的OpenGL ES 2.0

// Application to vertex shader 
varying vec3 N; 
varying vec3 I; 
varying vec4 Cs; 

void main() 
{ 
    vec4 P = gl_ModelViewMatrix * gl_Vertex; 
    I = P.xyz - vec3 (0); 
    N = gl_NormalMatrix * gl_Normal; 
    Cs = gl_Color; 
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; 
} 

这个shader工作与我在OSX上运行我的3D模型。但是,我试图获得运行openFrameworks和Android的openGL ES 2.0的相同模型。我的3D模型加载正常,我的片段着色器似乎正在为openGL ES 2.0编译。但是,我的顶点着色器不会编译。有谁知道我可以如何更改此代码,以便它可以在Android上运行?

这是我在logcat中看到:

08-29 13:47:24.499: V/ofShader(26349): checkAndCreateProgram(): creating GLSL program 

08-29 13:47:24.499: E/ofShader(26349): setupShaderFromSource(): GL_VERTEX_SHADER shader failed to compile 

08-29 13:47:24.499: E/(26349): ofShader: GL_VERTEX_SHADER shader reports: 

08-29 13:47:24.499: E/(26349): Vertex shader compilation failed. 

08-29 13:47:24.499: E/(26349): ERROR: 0:8: 'gl_ModelViewMatrix' : undeclared identifier 

08-29 13:47:24.499: E/(26349): ERROR: 0:8: 'gl_Vertex' : undeclared identifier 

08-29 13:47:24.499: E/(26349): ERROR: 0:8: '=' : cannot convert from 'float' to '4-component vector of float' 

08-29 13:47:24.499: E/(26349): ERROR: 0:10: 'gl_NormalMatrix' : undeclared identifier 

08-29 13:47:24.499: E/(26349): ERROR: 0:10: 'gl_Normal' : undeclared identifier 

08-29 13:47:24.499: E/(26349): ERROR: 0:10: 'assign' : cannot convert from 'float' to 'varying 3-component vector of float' 

08-29 13:47:24.499: E/(26349): ERROR: 0:11: 'gl_Color' : undeclared identifier 

08-29 13:47:24.499: E/(26349): ERROR: 0:11: 'assign' : cannot convert from 'float' to 'varying 4-component vector of float' 

08-29 13:47:24.499: E/(26349): ERROR: 0:12: 'gl_ModelViewProjectionMatrix' : undeclared identifier 

08-29 13:47:24.499: E/(26349): ERROR: 0:12: 'assign' : cannot convert from 'float' to 'Position 4-component vector of float' 

08-29 13:47:24.499: E/(26349): ERROR: 10 compilation errors. No code generated. 

08-29 13:47:24.499: V/ofShader(26349): setupShaderFromSource(): GL_FRAGMENT_SHADER shader compiled 

08-29 13:47:24.499: V/(26349): linkProgram(): attaching GL_FRAGMENT_SHADER shader to program 22 

08-29 13:47:24.499: E/ofShader(26349): checkProgramLinkStatus(): program failed to link 
+0

你在GL日志看到什么错误? – Tommy 2014-08-29 18:42:30

+0

我编辑帖子以包含LogCat输出;谢谢。 – m27 2014-08-29 18:54:32

回答

2
vec4 P = gl_ModelViewMatrix * gl_Vertex; 
     ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^ nope 
I = P.xyz - vec3 (0); 
N = gl_NormalMatrix * gl_Normal; 
    ^^^^^^^^^^^^^^^ ^^^^^^^^^ nope 
Cs = gl_Color; 
    ^^^^^^^^ nope 
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; 
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^ nope 

ES 2.0不提供这些内置插件。你必须使用通用的制服/属性自己提供/计算它们。

ES 2.0只提供在顶点着色器阶段两个内置变量:

highp vec4 gl_Position; // should be written to 
mediump float gl_PointSize; // may be written to 

GLSL ES 1.0 spec,第7.1节,第59页。

+0

非常感谢!我会努力改变这一点。 – m27 2014-08-30 01:46:21