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
}
uj5u.com熱心網友回復:
我解決了這個問題如下。在需要時,我繼承了相應的核心組態檔,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://www.uj5u.com/shujuku/417435.html
標籤:
上一篇:Qt創建者洗掉了檔案并且無法恢復
