在initializeGL()
失败后,我会遇到下面的段错误。对是什么原因有什么想法吗?当我从QOpenGLFunctions
继承时没有问题,但我需要v3.0功能。
class MyGLWidget : public QOpenGLWidget, protected QOpenGLFunctions
QOpenGLFunctions_3_3_Compatibility::glClearColor (this=0x5d3c40, red=0, green=0, blue=0, alpha=1) at /usr/include/qt5/QtGui/qopenglfunctions_3_3_compatibility.h:1064
1064 d_1_0_Core->f.ClearColor(red, green, blue, alpha);
class MyGLWidget : public QOpenGLWidget, protected QOpenGLFunctions_3_3_Compatibility
{
Q_OBJECT
...
};
void initializeGL() override {
makeCurrent();
bool ret = initializeOpenGLFunctions();
std::cout << std::boolalpha << ret << std::endl; // FALSE
glClearColor(0, 0, 0, 1); // CRASH
}
发布于 2022-01-18 07:32:21
我解决了这个问题如下。我继承了QOpenGLFunctions
,然后在需要时使用相应的核心配置文件3.3
。
class MyGLWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
...
protected:
void initializeGL() override {
initializeOpenGLFunctions();
auto * glFunctions = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_3_3_Core>();
glFunctions->glClearColor(0, 0, 0, 1);
}
};
https://stackoverflow.com/questions/70751049
复制相似问题