I have a small visualization framework written in c++ and want to use Qt to have a proper GUI and control over my visualizations to interact with them. currently, I am using GLUT to create a window and draw a view in it. so everything I do is initialize an object of the class Visualization which does everything for me: holding model and views. the view itself holds a controller to process user input and manipulate the model. my main loop looks like this:
Visualization* vis = new Visualization();
vis->createModel("some_file.txt");
vis->createView("unknown");
// ...
void demo_app::display()
{
// clear the framebuffer
glClearColor(0.3, 0.3, 0.3, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
vis.update(); // looks for dirty scenes to update
vis.render(); // draws all views which are stored in vis
glutSwapBuffers();
}
with GLUT I have a single window in which I arrange multiple views. when I order the view to draw during the main loop I can execute glCommands and everything is fine.
so now my problem is I want to use Qt with several windows (QDialogs
+QGLWidgets
). I am familiar with Qt and I already ported the framework to Qt. but the problem is that I have to do too much Qt integration within the framework and this is not what I want. I want to control the visualization with Qt and its GUI elements, but the draw call for a view should be made by my Visualization class as shown by the GLUT example. So there must be a way to give an inherited QGLWidget
a pointer to a view object and whenever the view should be drawn the widget has to call makeCurrent()
so the glCommands can draw on the context.
I also can use a texture in which my view paints the current scene and then draw the texture in the paintGL or glDraw()
function of the QGLWidget
, but how can I tell the Widget to update()
when the view has no knowledge about it.
I will emulate the main loop with a QTimer
set to 0. all I want to do is to be able to trigger the rendering of the QGLWidget
from inside my framework. any suggestion? links? examples?