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. QOpenGLContext fail makeCurrent(surface)
QtWS25 Last Chance

QOpenGLContext fail makeCurrent(surface)

Scheduled Pinned Locked Moved General and Desktop
qopenglcontextmakecurrent
8 Posts 3 Posters 8.1k 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.
  • X Offline
    X Offline
    Xv1nX
    wrote on last edited by Xv1nX
    #1

    Hi guys,

    i want to create a UI with QT for my existed OpenGL programm. So i created a QWindow with OpenGLSurface and also an OpenGLContext. Everything went well, but the call mOpenGLContext->makeCurrent(this) always fails. Anybody know why? in this case: "this" is an instance of QWindow with OpenGLSurface:

     OpenGLWindow::OpenGLWindow( QWindow *parent /*= 0*/ )
           :QWindow(parent)
          ,mOpenGLContext(NULL)
          {
                setSurfaceType(QSurface::OpenGLSurface);
          }
    
    
    void OpenGLWindow::createOpenGLContext( )
    {
    if(!mOpenGLContext){
        mOpenGLContext = new QOpenGLContext(this);
        QSurfaceFormat format = requestedFormat();
        mOpenGLContext->setScreen(this->screen);
        mOpenGLContext->create();
        if(mOpenGLContext->isValid() && mOpenGLContext->makeCurrent(this)){
            emit runCS();
        }else{
             msgWindow.setWindowTitle("Error");
             msgWindow.setIcon(QMessageBox::Critical);
             msgWindow.setText("Error: can not create OpenGLContext:\n");
             msgWindow.exec();
        }
      }
    }
    

    NOTE: Using QOpenGLWindow the programm appears with blank window for 2-5 seconds. It seems the initializeGL method is called after a while. That´s why i want to create my own QOpenGLContext.

    Thanks in advance for help,
    Vince

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Is the window shown before you call createOpenGLContext()? If not then the underlying surface might not be created yet. In that case you need to call create() manually before making a context current on that surface.

      X 1 Reply Last reply
      1
      • Chris KawaC Chris Kawa

        Is the window shown before you call createOpenGLContext()? If not then the underlying surface might not be created yet. In that case you need to call create() manually before making a context current on that surface.

        X Offline
        X Offline
        Xv1nX
        wrote on last edited by
        #3

        @Chris-Kawa
        Thank you Chris, but i already called create().

        1 Reply Last reply
        1
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by Chris Kawa
          #4

          Just to clarify: you called create() on the context. I meant to call create() on the window. Did you do that as well?

          X 1 Reply Last reply
          2
          • Chris KawaC Chris Kawa

            Just to clarify: you called create() on the context. I meant to call create() on the window. Did you do that as well?

            X Offline
            X Offline
            Xv1nX
            wrote on last edited by
            #5

            @Chris-Kawa
            Ahh thanks. It solves my problem. You are the man of the day!

            1 Reply Last reply
            0
            • V Offline
              V Offline
              Vince Golubic
              wrote on last edited by
              #6

              Any more information on what happens after the blank window appears? What does 'always fails' mean ?
              For instance, do you get a SEG Fault, bus err, are any error messages thrown? Does the application completely stop or freeze or is it just a blank rendering area ?

              • Vince
              X 1 Reply Last reply
              0
              • V Vince Golubic

                Any more information on what happens after the blank window appears? What does 'always fails' mean ?
                For instance, do you get a SEG Fault, bus err, are any error messages thrown? Does the application completely stop or freeze or is it just a blank rendering area ?

                • Vince
                X Offline
                X Offline
                Xv1nX
                wrote on last edited by
                #7

                @Vince-Golubic

                I mentioned 2 methods to create an area for drawing OpenGL directly.
                1. Method: Create QWindow and QOpenGLContext your own. Here i forgot to call manually QWindow::create().
                2. Method: Just inherit QOpenGLWindow and call your own draw method in paintGL(). With this method my programm shows a blank window for about 2-5 seconds, then openGL things appear. It seems the initializeGL() method is called far too late. If you guys have any idea how to speed up it, i would very appreciate to know.

                1 Reply Last reply
                0
                • Chris KawaC Offline
                  Chris KawaC Offline
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Looking at the source code of QOpenGLWindow the context creation happens on the first draw request. I don't see a way to force it earlier or set a ready made context, so this will always produce a visual gap. It's not that bad on my machine (0.5s to 1s) but it's noticeable.
                  I guess you could file a bug report on this.

                  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