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. Correct usage of QOpenGLContext??? [SOLVED]
Forum Updated to NodeBB v4.3 + New Features

Correct usage of QOpenGLContext??? [SOLVED]

Scheduled Pinned Locked Moved Game Development
9 Posts 3 Posters 12.7k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    Seraph
    wrote on last edited by
    #1

    Hi there everybody,

    I want to create a simple example for using a QOpenGLContext in QT5.
    I have found "this":http://www.youtube.com/watch?v=VxsS7u-vgc8 YouTube example and followed the steps exactly.
    One cannot see everything especially not the main function.

    I have written a simple class deriving from QWindow (as you can see in the video).

    @
    //header file
    class Window: public QWindow
    {
    private:
    QOpenGLContext *_glContext;
    public:
    Window(QScreen *screen=0);
    }@

    @
    //.cpp file

    Window::Window(QScreen *screen): QWindow(screen)
    {
    setSurfaceType(OpenGLSurface);

    QSurfaceFormat fmt;
    fmt.setMajorVersion(4);
    fmt.setMinorVersion(2);
    fmt.setProfile(QSurfaceFormat::CoreProfile); //whatever this is

    this->setFormat(fmt);

    create();

    resize(300, 300);

    _glContext = new QOpenGLContext();
    _glContext->setFormat(fmt);

    _glContext->create();

    if(!_glContext->isValid())
    qCritical()<<"The OpenGL context is invalid!"; //I allways get this message

    //now another test:
    //the next line prints: "Window format version is: 4.2" which is correct
    qDebug()<<"Window format version is: "<<this->format().majorVersion()<<"."<<this->format().minorVersion();
    //the next line prints: "Context format version is: 2.0" Which is ofcourse not correct! WTF?
    qDebug()<<"Context format version is: "<<_glContext->format().majorVersion()<<"."<<_glContext->format().minorVersion();
    }
    @

    As you can see, the format of the Window does not match the format of the context!!??!??
    Is this a bug or am i missing something?? Maybe i do it wrong in the main, already?

    @
    #include "window.h"
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    a.setApplicationName("test");
    a.setApplicationVersion("0.1");

    Window w; //do i have to create a QScreen first to give it to the Window?
    w.show(); //A white window of size 300x300 appears
    }@

    I need to have a OpenGL 4.2 context!

    Any help would be nice!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Seraph
      wrote on last edited by
      #2

      I also found this "example":http://qt-project.org/doc/qt-5.0/qtgui/openglwindow.html. It is one of the view QT5 examples delivered with the QT5.0.0 framework

      But this seems to be an example for OpenGL ES2. If i set the format version of the window to anything >2.9 the whole example crashes!
      I wish i had the example from the youtube video as code! He used 3.3 by the way which is not working in my case, either.

      I mean can i somehow setup my QT project by telling it to use OpenGL desktop version?
      Or do I have to recompile the whole framework and setting the open gl module with configure?

      Does nobody know anything about that?

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        ZapB
        wrote on last edited by
        #3

        Hi,

        What platform are you on?

        Are you using self-compiled Qt or the released binary packages?

        Nokia Certified Qt Specialist
        Interested in hearing about Qt related work

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Seraph
          wrote on last edited by
          #4

          Im working with Windows8 and i am using the released package (msvc2010)

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            ZapB
            wrote on last edited by
            #5

            Ah in that case, have a read of this "post":http://qt-project.org/forums/viewthread/22821/#107114 which explains the issue and solution. Please do vote on the linked bug report.

            Nokia Certified Qt Specialist
            Interested in hearing about Qt related work

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Seraph
              wrote on last edited by
              #6

              Thanks ZapB. I voted for this ticket

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Seraph
                wrote on last edited by
                #7

                Hi again. I did compile the framework in windows and Ubuntu 12.
                Now in windows i get a 4.2 context!
                But in Ubuntu it is still the same. But now i only get a 2.0 window format and a 2.1 context??? What is the right command to start the configure skript?

                I used:
                @./configure -prefix $PWD/qtbase -opensource -nomake tests -opengl desktop -developer-build@
                And then
                @make -j 4@

                ???

                By the way, our graphics driver supports OpenGL 4.2! The context in our QT 4.8.4 version of our project returned 4.2 and was able to use at least Shaders of version 3.3

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Seraph
                  wrote on last edited by
                  #8

                  OK. It's me again. I just builded an example with rendering part and i recognized that the created context is perfectly rendering and using shaders of version 3.3 !!!!! (didn't test any higher shader version, but i guess it would also work)

                  So maybe that is a bug?? The context format returns 2.1 right after creating it but it renders 3.3 shaders without any problem!
                  In Windows the same code returns 4.2 and it is also rendering without problems!

                  Merry X Mas and a happy end of the world (today the maya calendar ends! :D )

                  1 Reply Last reply
                  0
                  • U Offline
                    U Offline
                    unixmania
                    wrote on last edited by
                    #9

                    This my post is my own correct usage.Working perfectly.
                    it is HOWTO using "QOpenGLFunctions_3_3_Core" class.
                    There is no need Q_OBJECT macro.
                    There is no need to define custom signal or slot.
                    There is no need to define any connections.
                    I put it as be reference:)

                    http://qt-project.org/wiki/Using-QOpenGLFunctions-and-QOpenGLContext

                    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