I study 3D programming with the book Learning Modern 3D Graphics Programming , but I was out of luck with shaders and GLES 2.0 on iOS. I am working with the opengl xcode 4 game template, although the changes make sense for the first example in the book.
The first shaders in the book will not compile with many different errors. First vertex shader
#version 330 layout(location = 0) in vec4 position; void main() { gl_Position = position; }
He complains about the version approval and refuses to allow the use of the layout as a specifier. I finally managed to create this.
attribute vec4 position; void main() { gl_Position = position; }
Again, the first fragment shader refuses to build due to the version and will not allow output in the global segment
With an error
ERROR: 0:10: Invalid qualifiers 'out' in global variable context
Ok, so I managed to get the first example (a simple triangle) for working with the following shaders.
vertex shader
fragment shader
attribute vec4 position; void main() { gl_Position = position; }
So, they worked, and I tried the first color example in the next chapter.
#version 330 out vec4 outputColor; void main() { float lerpValue = gl_FragCoord.y / 500.0f; outputColor = mix(vec4(1.0f, 1.0f, 1.0f, 1.0f), vec4(0.2f, 0.2f, 0.2f, 1.0f), lerpValue); }
Even working with fixed problems from the eariler, the version, f in the floats is not resolved, the shader still refuses to build with this error
ERROR: 0:13: 'float' : declaration must include a precision qualifier for type
In fact, he complains about the float.
I tried a Google search to find an explanation of the differences, but none of them appeared. I also read apple documents that were looking for advice and did not find any help. I'm not sure where else to look, or what I'm really doing wrong.