c++ - Setting Up OpenGL in Qt for QOpenGLWidget -


i have old opengl code created glew. trying port code qt 5.4, old code contains mesh, shader, , texture classes.

what have far in qt, default main window , visualizer class inherits qopenglwidget , qopenglfunctions. able display widget black box setting mainwindow parent of visualizer.

in order compile old opengl code uses functions glgenvertexarrays(); made classes inherit qopenglfunctions_3_3_core. call initializeopenglfunctions() necessary such inside initializegl() of visualizer class , in constructors of mesh, shader, , texture.

it compiles well. when run program crashes when function glgenvertexarrays(); called when trying create mesh object.

i guessing there memory violation of sort. have setup opengl context in qt manually qopenglwidget?

how can setup opengl 3.3 qt can use qopenglwidget render opengl content , use of opengl functions such glgenvertexarrays() ?

i came interesting solution. perhaps obvious didn't see @ first. created single static variable of type qopenglfunctions_3_3_core inside dummy class, gl, , used through out entire code whenever opengl function needed.

for example

class gl{   public:     static qopenglfunctions_3_3_core funcs; }  ...  class visualizer : public qopenglwidget{     ...     void initializegl(){       gl::funcs.initializeopenglfunctions();    }    ... }  ...  // example usage gl::funcs.glgenvertexarrays(1, &id); gl::funcs.glclearcolor(1.f, 1.f, 1.f, 1.f); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -