How to change opengl app that creates two opengl windows to qt?
-
wrote on 11 Nov 2015, 14:32 last edited by
Hi,
I try to use qt in my app and I found that there is opengl in Qt. I read lots of tutorials, but I am wondering one thing.
In my app I have part of code responsible for creating two windows. In each window there is different view.void run() { glutInit(&m_argc, m_argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_DOUBLE); glutInitWindowSize(m_width, m_height); m_arWindow = glutCreateWindow("AR"); glutDisplayFunc(drawAr); glutSpecialFunc(keyCallback); glutPositionWindow(0, 0); m_vrWindow = glutCreateWindow("VR"); glutDisplayFunc(drawVr); glutPositionWindow(0, m_height); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glEnable(GL_COLOR_MATERIAL); glutMouseFunc(mouse); glutMotionFunc(motion); glutMainLoop(); }
If I want to subclass QGLWidget, I have to do this for each window (create one class based on QGLWidget for each window)? Or I should create only one class and in paintGL() method I should use both function?
-
Hi,
Since you have two windows, you are likely showing something different on each, right ? If so then build two widgets. By the way, if you are using Qt 5, you should start directly with QOpenGLWidget.
-
Hi,
Since you have two windows, you are likely showing something different on each, right ? If so then build two widgets. By the way, if you are using Qt 5, you should start directly with QOpenGLWidget.
wrote on 12 Nov 2015, 15:43 last edited by never_ever 11 Dec 2015, 18:16@SGaist So, I have to subclass QOpenGLWidget twice. Once for class creating one window, second for class creating second window? What if in my version I had above function in other thread (it was necessary in my app)? If I have to subclass also QThread in that classes and create two additional threads for them?
If I use QOpenGlWidget is there any corresponding function to glutSwapBuffers? In QGlWidget I see swapBuffers(), but in QOpenGLWidget I don't.
-
Take a look at the examples in Qt's documentation, there's one showing how to use thread and QOpenGLWidget
1/4