c++ - OpenGL with QT error: ASSERT:"QOpenGLFunctions::isInitialized(d_ptr)". Unable to create OpenGL context -
i have made first opengl program rendering cube, extended include other basic features (rotate, zoom, pan, mouse selection of vertices). however, think program using version of opengl es x.x because not use glreadpixels gl_depth_component enable mouse selection of visible vertices.
to fix i've modified old program manually specify default surface format in main function opengl version 3.0, program throws following error when tries create instance of glwidget.
assert:"qopenglfunctions::isinitialized(d_ptr)"
my main function (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 w.show(); return a.exec(); }
stepping breakpoint leads me mainwindow constructor(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 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, slot(setfaces())); connect(ui->actionfind_vertex,signal(triggered(bool)),ui->glwidget2,slot(startvertexsearch())); connect(ui->actionfit_to_screen,signal(triggered()),ui->glwidget2,slot(fittoscreen())); connect(ui->pushbutton_selectmode,signal(released()),ui->glwidget2,slot(setselectmode())); connect(ui->pushbutton_cancelselect,signal(released()),ui->glwidget2,slot(setcancelselectmode())); }
stepping breakpoint leads me ui_mainwindow.h, creates objects in mainwindow , reaches line:
[code above...]
pushbutton = new qpushbutton(centralwidget); pushbutton->setobjectname(qstringliteral("pushbutton")); verticallayout_2->addwidget(pushbutton); horizontallayout->addlayout(verticallayout_2); glwidget2 = new glwidget(centralwidget); /break point here - step
[code below...]
this runs fine until constructor of glwidget called... (glwidget.cpp)
#include "glwidget.h" glwidget::glwidget(qwidget *parent = 0) : qopenglwidget(parent) { //breakpoint here alpha = 0; beta = 0; distance = defaultdistance; qsurfaceformat format; format.setsamples(16); format.setdepthbuffersize(24); format.setversion(3,0); format.setprofile(qsurfaceformat::coreprofile); this->setformat(format); }
as continue past breakpoint assert error thrown. debugging leads me place in qopenglfunctions.h
[code above...]
inline gluint qopenglfunctions::glcreateprogram() { #ifdef qt_opengl_es_2 gluint result = ::glcreateprogram(); #else q_assert(qopenglfunctions::isinitialized(d_ptr)); //this line gluint result = d_ptr->createprogram(); #endif q_opengl_functions_debug return result; }
[codde below...]
the value of d_ptr @ time null, guess cause of error. need perform initialisation of desktop opengl versions aren't required opengl es versions?
i'm still new opengl appreciated!
update i'm not sure happening, after merging updated code older working code worked fine. happens no-one else!
you need add initializeopenglfunctions();
glwidget::initgl()
function.
Comments
Post a Comment