Search code examples
androidopengl-esglslglsles

OpenGL ES GLSL shader on Android not loading correct version?


I'm following this example on rendering the camera preview using GLES 2.0 (http://maninara.blogspot.com/2012/09/render-camera-preview-using-opengl-es.html). It worked great until I copied some GLSL shader code from somewhere else and noticed it didn't work and I get this error:

error C7502: OpenGL does not allow type suffix 'f' on constant literals in versions below 120

So to see if the problem was from my copied shader code, I changed this line in the vertex shader example (see link above) from

gl_Position = vec4 ( vPosition.x, vPosition.y, 0.0, 1.0 )

to

gl_Position = vec4 ( vPosition.x, vPosition.y, 0.0f, 1.0f )

but I still get the same error. I've confirmed GLSL's version is high enough by outputting GLES20.glGetString(GLES20.GL_SHADING_LANGUAGE_VERSION) which gives:

GLSL Version = OpenGL ES GLSL ES 3.10

Am I setting up my OpenGL ES context incorrectly? What's going on here?

UPDATE: If I add "#version 120", I get this error:

error C0201: unsupported version 120

Solution

  • Why did you add the f suffix when the compiler did tell you that it is not supported? These suffixes actually do not mean anything in GLSL, and literals are single precision by default anyway - there is the lf suffix for double precision.

    It seems like there is some f suffix somewhere else in that shader, and it won't compile until that is removed.

    I've confirmed GLSL's version is high enough by outputting > GLES20.glGetString(GLES20.GL_SHADING_LANGUAGE_VERSION) which gives:

    GLSL Version = OpenGL ES GLSL ES 3.10

    That just says that the implementation is supporting up to GLSL ES 3.10, not that you are using it. If you have no #version directive in your shader sources, the default #version 100 ES will be used.