I’m trying to implement some shaders from online tutorials (lighthouse3d.com) in my OpenGL ES 2.0 engine.
The problem is that for some reason, ANY variables declared in the scope of main() causes the entire shader to fail. for example, this fails:
void main(){
vec4 color;
gl_FragColor = vec4(1.0, 0.5, 0.5, 1.0);
}
but this works perfectly:
void main(){
//vec4 color;
gl_FragColor = vec4(1.0, 0.5, 0.5, 1.0);
}
Same thing happens with my vertex shaders.(EDIT:nvm, only seems to happen with fragment shaders) The only way to use any type of non-constant value is to use attributes, varyings, uniforms, etc. for example, this works as you would expect:
uniform sampler2D texture;
varying lowp vec4 fragcol;
varying lowp vec2 texco;
void main(){
gl_FragColor = fragcol * texture2D(texture, texco);
}
Also, I’m having a hell of a lot of trouble trying to find documentation or resources specifically about GLSL ES (or whatever this version is called). All I’ve been able to find is this: http://old.siggraph.org/publications/2006cn/course16/KhronosSpecs/ESLanguageSpec1.10.11.pdf
This is all I could find related to variable declarations:
[snip]There are no default types. All variable and function declarations
must have a declared type, and optionally qualifiers. A variable is
declared by specifying its type followed by one or more names
separated by commas.[snip]
And that is exactly what I did:
declared type: vec4
followed by one or more names: color;
vec4 color
I’m clueless
EDIT:
GLES20.glGetError() gives error 1282
GLSL ES differs from traditional GLSL in that it requires precision modifiers in order to specify a full type. Have you tried, e.g.:
You can also throw something like this into the top of a source file:
To set the default precision, so you can omit it later on.
To get detailed information about an error compiling GLSL, you can use
glGetProgramInfoLog(with assistance fromglGetProgramiv). Most GL implementations return a meaningful error and a line number. I’m sadly backward with Java, but in C you might do: