小编sca*_*tat的帖子

带有QT错误的OpenGL:ASSERT:"QOpenGLFunctions :: isInitialized(d_ptr)".无法创建OpenGL上下文

我最近制作了第一个渲染立方体的OpenGL程序,我将其扩展到包括一些其他基本功能(旋转,缩放,平移,鼠标选择顶点).但是,我认为该程序使用的是某些版本的OpenGL ES xx,因为我无法使用glReadPixels和gl_depth_component来启用鼠标选择仅可见顶点.

为了解决这个问题,我修改了我的旧程序,在我的main函数中手动指定默认的表面格式为OpenGL 3.0版,但是现在程序在尝试创建GLWidget实例时会抛出以下错误.

宣扬: "QOpenGLFunctions ::将IsInitialized(应将d_ptr)"

我的主要功能(main.cpp):

#include "mainwindow.h"
#include <QApplication>
#include <QOpenGLFunctions>


int main(int argc, char *argv[])
{
    QSurfaceFormat format;
    format.setSamples(16);     
    format.setDepthBufferSize(24);
    format.setVersion(3,0);
    format.setProfile(QSurfaceFormat::CoreProfile);
    QSurfaceFormat::setDefaultFormat( format);
    QApplication a(argc, argv); 
    MainWindow w;                                          //breakpoint here - step into
    w.show();
    return a.exec();
}
Run Code Online (Sandbox Code Playgroud)

进入这个断点会引导我进入我的MainWindow构造函数(mainwindow.cpp):

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);                                       //breakpoint here - step into
    ui->GLwidget2->getmainwindowpointer(this);
    connect(ui->actionTop,SIGNAL(triggered()),ui->GLwidget2,SLOT(settopview()));
    connect(ui->actionRight, SIGNAL(triggered()), ui->GLwidget2, SLOT(setrightview()));
    connect(ui->actionIso,SIGNAL(triggered()),ui->GLwidget2,SLOT(setisoview()));
    //connect(ui->checkBox_perspective,SIGNAL(released()),ui->GLwidget2,SLOT(setperspective()));
    connect(ui->checkBox_legend, SIGNAL(released()), ui->GLwidget2, SLOT(setlegend()));
    connect(ui->checkBox_edges, SIGNAL(released()), ui->GLwidget2, SLOT(setedges()));
    connect(ui->checkBox_faces, SIGNAL(released()), ui->GLwidget2, …
Run Code Online (Sandbox Code Playgroud)

c++ opengl qt opengl-es

0
推荐指数
1
解决办法
3323
查看次数

标签 统计

c++ ×1

opengl ×1

opengl-es ×1

qt ×1