Android opengl es shader编译错误

时间:2013-07-09 13:38:24

标签: android opengl-es opengl-es-2.0 shader

我的android项目中出现了着色器编译错误,我不知道它有什么问题:

Shader compile error: Vertex shader compilation failed.
ERROR: 0:4: 'gl_FragColor' : undeclared identifier
ERROR: 0:4: 'assign' :  cannot convert from 'varying 4-component vector of float' to 'float'
ERROR: 2 compilation errors.  No code generated.

VertexShader:

uniform mat4 u_MVPMatrix;
attribute vec4 a_Position;
attribute vec4 a_Color;
varying vec4 v_Color;
void main() {
    v_Color = a_Color;
    gl_Position = u_MVPMatrix * a_Position;
}

Fragment Shader:

precision mediump float;
varying vec4 v_Color;
void main() {                         
  gl_fragcolor = v_Color;
} 

顶点着色器编译完美,但片段着色器不起作用。 由于代码来自教程,它应该工作,当我启动教程项目时,没有编译错误。我不明白,因为我现在多次复制着色器代码1:1,但它仍然无效。

解决:我发现了问题......我是通过方法编译着色器但是方法总是使用glCreateShader(GL_VERTEX_SHADER);难怪它无法编译片段着色器。这就是为什么在日志中它说'顶点着色器编译失败',这样的转储错误需要花费数小时... ^^

1 个答案:

答案 0 :(得分:4)

GLSL与C一样,区分大小写。

试试gl_FragColor。注意CamelCase。