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 25 Mar 2015, 14:10 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
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 25 Mar 2015, 14:17 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 25 Mar 2015, 14:19
      1
      • C Chris Kawa
        25 Mar 2015, 14:17

        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 25 Mar 2015, 14:19 last edited by
        #3

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

        1 Reply Last reply
        1
        • C Offline
          C Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on 25 Mar 2015, 14:20 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 25 Mar 2015, 14:31
          2
          • C Chris Kawa
            25 Mar 2015, 14:20

            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 25 Mar 2015, 14:31 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 25 Mar 2015, 14:42 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 25 Mar 2015, 14:51
              0
              • V Vince Golubic
                25 Mar 2015, 14:42

                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 25 Mar 2015, 14:51 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
                • C Offline
                  C Offline
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on 25 Mar 2015, 15:21 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

                  3/8

                  25 Mar 2015, 14:19

                  5 unread
                  • Login

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