Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. QGLShaderProgram GLSL ES 2 shaders not compiling
Forum Update on Monday, May 27th 2025

QGLShaderProgram GLSL ES 2 shaders not compiling

Scheduled Pinned Locked Moved Game Development
4 Posts 4 Posters 5.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mirx
    wrote on last edited by
    #1

    Hi all,
    I'm developing a Qt / Linux x11 application that uses GLSL shaders over openGL ES but I have some issues on the precision identifiers.

    When I compile and link my simple QGLShaderProgram I get this error:
    @
    QOpenGLShader::compile(Fragment): 0:6(16): error: no precision specified this scope for type `vec4'

    *** Problematic Fragment shader source code ***
    #version 100
    #define lowp
    #define mediump
    #define highp

    varying highp vec4 outColor;

    void main(void)
    {
    gl_FragColor = outColor;
    }


    @

    The problem is that the definitions of lowp, mediump and highp are automatically added to my shader source code as described in the documentation "documentation":https://qt-project.org/doc/qt-5/qglshaderprogram.html#details and the effect is that the precision identifiers are ignored.

    With the first line I'm forcing the GLSL version to be the ES 2 standard where the precision identifiers are mandatory but the definitions are generated anyhow.

    If I explicitly undefine those definitions the shader works well but I'm sure that's not the right way to do.

    Why these definitions are added?
    What's the right way to write a portable shader code?

    Thank you very much
    Mirx

    1 Reply Last reply
    0
    • P Offline
      P Offline
      pippox
      wrote on last edited by
      #2

      I've also seen this problem in the wild.

      Is anybody willing to explain why those three defines are autogenerated??

      1 Reply Last reply
      0
      • A Offline
        A Offline
        agocs
        wrote on last edited by
        #3

        Because when Qt is configured for desktop (non-ES) OpenGL, it will add those dummy defines to make sure a shader targeted for ES still compiles.

        The portable way is to omit the #version and write ES2 shaders. These will then work both on ES and desktop (where Qt will insert the dummy defines).

        1 Reply Last reply
        0
        • 8Observer88 Offline
          8Observer88 Offline
          8Observer8
          wrote on last edited by
          #4

          Hi! I use OpenGL ES too. Try "my example":https://github.com/8Observer8/TexturedTriangle

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved