Unsolved Qt5 and glew
-
Hi,
I have a problem with the initialization of glew. glewInit() dosen't return GLEW_OK.
class Viewer : public QWindow { private: QOpenGLContext* context_; QSurfaceFormat* format_; public: Viewer() { setGeometry(QApplication::desktop()->screenGeometry().width()/2-350, QApplication::desktop()->screenGeometry().height()/2-350, 700, 700); setSurfaceType(QWindow::OpenGLSurface); format_ = new QSurfaceFormat(); format_->setDepthBufferSize(24); format_->setStencilBufferSize(8); format_->setVersion(4, 3); format_->setSwapInterval(0); format_->setProfile(QSurfaceFormat::CoreProfile); setFormat(*format_); context_ = new QOpenGLContext(this); context_->setFormat(*format_); context_->create(); context_->makeCurrent(this); glewExperimental = true; if (glewInit() != GLEW_OK) { std::cout<<"GLEW isn't init."<<std::endl; } context_->doneCurrent(); } ~Viewer(); };
Best regards,
Robin -
Well first thing that strikes me is you're not doing any error checking.
create()
andmakeCurrent()
may very well fail so you should check that.
Other than that, if I remember correctly (I might not), the window isn't really created until it is first shown, so ceating and using context in the constructor is not the best place. You could deffer context creation until the firstshowEvent()
or use a QOffscreenSurface if you really need it in the constructor.
Also you are leakingformat_
. QSurfaceFormat is usually created on the stack and I strongly suggest that in this case.
Take a look at OpenGL Window Example to see how correct context creation can be handled. -
You're right. if I connect a slot like that in my constructor : "connect(&loop_, SIGNAL(timeout()), this, SLOT(render()));", I can init glew's function.
void Viewer::render() { if (!context_) { glewInit(); } }
create() and makeCurrent() do not failed.
thanks you for the QOffscreenSurface tricks :)