How to setup QOpenGLWindow to have access to desirable functionality?

  • In my Qt OpenGL desktop application, I use some pre-2.0 aspects of openGL in combination with buffer arrays, flat shading, and simple lighting. I do not use shaders.

    The application is built with VS2013 and works fine on my Windows 10 development machine. However, when I tried to install and run it on Windows 7 I run into problems that I can't figure out how to deal with.

    Initially, I found out that simple GL functions refused to work. For example glEnable(GL_RESCALE_NORMAL) resulted in glGetError() returning GL_INVALID_ENUM. That prompted my checking of GL version. I discovered that if I don't set anything but sampling in the format of my QOpenGLWindow then inside of my initializeGL() method on Win7 I see QOpenGLContext with GL version 2.0 while it is 4.3 on Win10. I figured that Win7 must be trying to run GL 2.0 ES which does not support rescaling of normals.

    Next, I tried to give Qt some hints about my desired GL features. I added calls to set OpenGLContextProfile to QSurfaceFormat::CompatibilityProfile and RenderableType to QSurfaceFormat::OpenGL. I checked resulting QOpenGLContext and on Win10 it was just as I requested while on Win7 my settings were somewhat ignored and created QOpenGLContext had ContextProfile as CompatibilityProfileType but RenderableType changed to OpenGLES, and GL version was 2.0. glEnable(GL_RESCALE_NORMAL) still reported an error.

    Subsequently, I tried to be even more explicit and added calls to set major and minor versions of GL. That resulted in even stranger behavior. On my development Win10, the same code that worked okay without explicit setting of version after I set it to the same value as previously was selected by default stopped working. Now glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE) started reporting GL_INVALID_OPERATION error. Crazy.

    I fill lost. Where should I look?

  • Lifetime Qt Champion


    Did you check what kind of driver was available on Win7. It seems that the backend detection starts the ANGLE backend. You could try forcing the OpenGL mode to be desktop.

    See here for more information.

    Hope it helps

  • @SGaist Thanks for the suggestion. I think Win7 computer had d3d9 installed, but not d3d11 (will double check tomorrow when I get into the office). I did see the piece of documentation that you pointed out. However, I was confused by it. I developed everything using VS2013 with the latest studio plug-in and didn't have to deal with the configure script. I just compiled and linked. By the way, opengl32.dll is one of my link dependencies.

    • Does not using configure script implies that I would need to rebuild Qt from source?
    • If I do that wouldn't I loose the convenience of not thinking about specific graphics cards afforded by ANGLE?
    • Is it a bug that Qt would not make QOpenGLContext with render type OpenGL as opposed to OpenGLES when I explicitly asked for it? Is there a way to force OpenGL render type by requesting some specific version of OpenGL?

    ~ LR

  • Lifetime Qt Champion

    Indeed, configure means that you are building Qt yourself. The thing that was of interest to you is under that paragraph i.e. the use of AA_UseDesktopOpenGL to force the backend to desktop OpenGL.

    AFAIK, Qt queries the system to try to get what you asked and returns what the system provided as a answer.

    To request specific version and other options IIRC, it's the QSurfaceFormat that interests you.

  • I already tried using QSurfaceFormat to request render type QSurfaceFormat::OpenGL to no avail.

    The main point of your reply turned out to be very useful. I managed to overcome my problems by setting an environment variable QT_OPENGL=desktop (just wish the documentation was explicit about specific value to use).

    Calling QCoreApplication:::setAttribute(AA_UseDesktopOpenGL) is an even more elegant solution. I just wish I'd noticed that this method is static sooner and thus makes it easy to satisfy documentation requirement of being called before my application is instantiated.

    Your help is much appreciated.

  • @L_Raiz Hi Raiz, how did you set the environment variable QT_OPENGL=desktop? I set it in the System variable (advanced system settings -> advanced -> environment variables), but does not work. Also put it in the .pro file, do not work. I think I must have misunderstand something...

  • Lifetime Qt Champion

    Hi @lilyofvalley,

    You can do it in the Run part of the Project panel of Qt Creator

  • @SGaist Thank you so much! I will try it~~~

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.