Important: Please read the Qt Code of Conduct -

How to have qt5 work on desktop like on mobile devices (es2, correct glsl version) ?

  • Hi all and happy new year ! I am looking for help/information concerning this issue :

    My work: I have a render engine that works on an iOS app. I almost managed to make it work by calling the same openGL rendering engine from a Qt(4.8 first, then 5.0 since today) app with a QGLWidget. To support es2 function set my widget also inherits QGLFunctions.

    However I still have issues with shaders : I could not compile them on qt with glCompileShader because of almost every keywords (lowp, vec4, vec2 ...) were returning compilations errors. So I compiled it with QGLShader program, but I had to specify "#version 120", the closest to es2. But still, my sprites don't show up the right size and the only potentially influencing different pieces of code with iOS are in shader compilation / version. I think the issue in the shader is gl_PointSize not changing anything in qt's compilation of the vertex shader.

    Questions :

    What is the new good version of activating es2 now that QGLFuntions is obsolete in Qt5 ("": ? I did not found any documentation/tutorial on this, if you know one, please share.

    Is there any better way for me to have shaders compiled on qt like they are on iOS ? ( I know glsl es2 version is coming from version 120 but I don't know to what extent they differ ).

    The hello-gl-es2 example did not help me because glsl version also returns 1.20.

    I'll happily receive any hints, thank you !

    My shaders, working well on iOS but not on Qt:

    @const GLchar vShaderStr[] =
    #ifdef QT_OPENGL_LIB
    "#version 120\n" // necessary for Qt to compile shaders
    #endif //QT_OPENGL_LIB
    "attribute lowp vec4 Position;\n"
    "attribute mediump vec2 TextureCoord;\n"
    "attribute lowp float Weight;\n"
    "uniform mat4 MVP;\n"
    "varying mediump vec2 TextureCoordOut;\n"
    "void main(void)\n"
    " gl_Position = MVP * Position;\n"
    " TextureCoordOut = TextureCoord;\n"
    " gl_PointSize = Weight;\n"

    const GLchar fShaderStr[] =
    #ifdef QT_OPENGL_LIB
    "#version 120\n" // necessary for Qt to compile shaders
    #endif //QT_OPENGL_LIB
    "varying mediump vec2 TextureCoordOut;\n"
    "uniform sampler2D Sampler;\n"
    "uniform bool IsSprite;\n"
    "uniform lowp vec3 TextureColor;\n"
    "uniform lowp float Opacity;\n"
    "void main(void)\n"
    " lowp vec4 textureColorResult;\n"
    " textureColorResult = texture2D(Sampler, IsSprite ? gl_PointCoord : TextureCoordOut);\n"
    " gl_FragColor = IsSprite ? vec4(mix(textureColorResult.rgb,TextureColor, 1.0),\n"
    " textureColorResult.a * Opacity) : textureColorResult;\n"

  • I missed the Note: that appeared on the Qt5.0 doc of the obsolete classes linking to the classes that replace them. Seems that most of them is replaced by classes starting with QOpenGL instead of QGL and that have different usage. I will come back to say if I solved my issues with those new classes.

  • Finally solved this issue !

    I kept the #version 120 and found what was missing for it to work as it does on device. On desktop with qt(5.0 now) you have to activate following gl functions that seem to be default on iOS:

    @ glEnable(GL_POINT_SPRITE);

Log in to reply