Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using Legacy OpenGL calls with QT6

Using Legacy OpenGL calls with QT6

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 1.7k 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.
  • B Offline
    B Offline
    begleysm
    wrote on 1 Nov 2022, 18:53 last edited by
    #1

    Hello, I'm new to Qt and am trying to import some older C++ openGL code. I'm currently using Qt 6.4. I've subclassed my OpenGL-using class to QOpenGlFunctions.

    Many of the glFoo calls "work" but the class also uses calls like glEnableClientState, glVertexPointer, glNormalPointer, glTexCoordPointer, glDisableClientState, glColor4fv, & glMaterialfv which come up with errors like undefined reference to __imp_glTextCoordPointer. Looking at the documentation these appear to no long be supported by "default" but it looks like they are supported using older versions of QOpenGlFunctions such as QOpenGlFunction_1_4 (https://doc-snapshots.qt.io/qt6-dev/qopenglfunctions-1-4.html).

    Trying to change my subclass from QOpenGLFunctions to QOpenGLFunctions_1_4 complains that really only QOpenGLFunctions_1_4_CoreBackend and QOpenGLFunctions_1_4_DeprecatedBackend exist but there appears to be no documentation on those and if I subclass to one of them I start seeing complaints about my constructor...

    How do I actually access the functions from these older versions of the class?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 1 Nov 2022, 19:31 last edited by SGaist 11 Jan 2022, 19:49
      #2

      Hi and welcome to devnet,

      If memory serves well, these classes are automatically generated out of the corresponding specifications.

      Which error are you getting with them ?

      Also, on which platform are you building your code ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        begleysm
        wrote on 1 Nov 2022, 19:43 last edited by
        #3

        Thanks for the quick reply.

        To my knowledge, I haven't explicitly defined what OpenGL spec I'm targeting. I supposed it's just using the newest. A 2 minutes Google search, just now, didn't give me the answer on how to define the targeted spec but I'll keep looking for that.

        I'm on Windows 10 using Qt 6.4 with CMake 3.24.2, and GDB & G++ in MinGW 11.2.0, in Qt Creator 8.0.2. I'm building for Windows 10 right now (and want to later expand to Linux as well).

        Thanks.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 1 Nov 2022, 19:51 last edited by
          #4

          Sorry, there was a word missing (fixed now). I meant to ask which error are you getting ?

          The specifications used comes from the Khronos group.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • B Offline
            B Offline
            begleysm
            wrote on 1 Nov 2022, 20:09 last edited by
            #5

            The errors all take the form undefined reference to '__impglFoo'

            dbd800fd-2dfa-4b3d-9b4f-589010e048c4-image.png

            glDrawElements is a "supported" call. If you check QOpenGLFunctions you'll see it listed (but you won't see glDisableClientState)
            e4d33141-4267-49ac-89e2-84c704d9ce04-image.png

            glDisableClientState is an "unsupported" call. While it is not in QOpenGLFunctions If you check QOpenGLFunctions_1_4 you'll see it (and glDrawElements) listed.
            d42705b1-8578-4dac-8507-72f4d03ab7e6-image.png

            but you see that both calls are somewhat recognized as they have tooltips and they don't, initially, throw an error. In fact you can find them in gl.h
            890f1836-3489-46d9-94f4-f5cb229f95cf-image.png
            ccb8eade-d662-4627-abf3-e706b4d75033-image.png

            But the "older" set don't seem to have actualy functions to link against.

            So, ultimately, I'm just trying to figure out how to specify that I want to use one of these older specifiations (I think).

            Thanks for your time.

            1 Reply Last reply
            0
            • C Online
              C Online
              Chris Kawa
              Lifetime Qt Champion
              wrote on 1 Nov 2022, 20:12 last edited by Chris Kawa 11 Jan 2022, 20:14
              #6

              OpenGL 3.1 introduced profiles. Core profile does not support these old functions and Compatibility profile does.
              So first you have to make sure you have a context in version either lower than 3.1 (which does not support profiles) or 3.1 and up set up to use Compatibility profile. AFAIK Qt does not support OpenGL < 3.1 anymore, so you only have the latter option.

              If you're not sure what context you have you can simply do qDebug() << your_context and it will print out all the parameters, or you can query individual fields of it e.g. your_conext->format()->profile(). If your context is not set correctly the simplest way is to set it up like this before any OpenGL is initialized in your app:

              QSurfaceFormat fmt;
              fmt.setVersion(3,1);
              fmt.setProfile(QSurfaceFormat::CompatibilityProfile);
              fmt.setOptions(QSurfaceFormat::DeprecatedFunctions);
              QSurfaceFormat::setDefaultFormat(fmt);
              

              When you have the correct context you can access the deprecated functions like this:

              QOpenGLFunctions_1_4* funcs = QOpenGLVersionFunctionsFactory::get<QOpenGLFunctions_1_4>(context());
              if(funcs)
              {
                  //do OpenGL 1.4. stuff, for example
                  funcs->glEnableClientState(GL_VERTEX_ARRAY);
              }
              else
              {
                  // Not a valid context?
              }
              
              1 Reply Last reply
              3
              • C Online
                C Online
                Chris Kawa
                Lifetime Qt Champion
                wrote on 1 Nov 2022, 20:26 last edited by Chris Kawa 11 Jan 2022, 20:27
                #7

                As for your screenshots - gl.h is a vanilla OpenGL header provided by your toolchain (MinGW in your case).
                You can't use the gl* functions from the gl.h header directly. Those are just function signatures that need to be dynamically resolved first from the implementation provided by your graphics card driver. That's why you're seeing the unresolved externals errors when you try to use them.

                Qt does that resolving for you, but, unlike the raw OpenGL header, it splits them into the Forward and Deprecated functions and puts them in QOpenGLFunctions and the QOpenGLFunctions_X_X classes. The easiest way to use the forward functions is to subclass QOpenGLFunctions, but to get the deprecated QOpenGLFunctions_X_X instance you go through a factory like I posted above.

                1 Reply Last reply
                2
                • B Offline
                  B Offline
                  begleysm
                  wrote on 1 Nov 2022, 20:48 last edited by
                  #8

                  Thanks you @Chris-Kawa (and @SGaist)! This looks like exactly what I was needing. I'll dig in with this and report back my results.

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    begleysm
                    wrote on 1 Nov 2022, 21:23 last edited by
                    #9

                    Not everything is working 100% but I am able to use those legacy functions from QOpenGLFunctions_1_4. Thanks!

                    1 Reply Last reply
                    0

                    8/9

                    1 Nov 2022, 20:48

                    • Login

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