Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to change opengl app that creates two opengl windows to qt?



  • 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?


  • Lifetime Qt Champion

    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.



  • @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.


  • Lifetime Qt Champion

    Take a look at the examples in Qt's documentation, there's one showing how to use thread and QOpenGLWidget


Log in to reply