QOpenGLContext fail makeCurrent(surface)
-
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 -
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. -
@Chris-Kawa
Thank you Chris, but i already called create(). -
Just to clarify: you called
create()
on the context. I meant to callcreate()
on the window. Did you do that as well? -
@Chris-Kawa
Ahh thanks. It solves my problem. You are the man of the day! -
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
-
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. -
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.