Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    QOpenGLContext fail makeCurrent(surface)

    General and Desktop
    qopenglcontext makecurrent
    3
    8
    6256
    Loading More Posts
    • 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
      Xv1nX last edited by Xv1nX

      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 Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by

        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 Reply Quote 1
        • X
          Xv1nX @Chris Kawa last edited by

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

          1 Reply Last reply Reply Quote 1
          • Chris Kawa
            Chris Kawa Moderators last edited by 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 1 Reply Last reply Reply Quote 2
            • X
              Xv1nX @Chris Kawa last edited by

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

              1 Reply Last reply Reply Quote 0
              • V
                Vince Golubic last edited by

                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 Reply Quote 0
                • X
                  Xv1nX @Vince Golubic last edited by

                  @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 Reply Quote 0
                  • Chris Kawa
                    Chris Kawa Moderators last edited by

                    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 Reply Quote 0
                    • First post
                      Last post