Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to change opengl app that creates two opengl windows to qt?
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
opengl
4 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    never_ever
    wrote on 11 Nov 2015, 14:32 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 11 Nov 2015, 22:27 last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      N 1 Reply Last reply 12 Nov 2015, 15:43
      0
      • S SGaist
        11 Nov 2015, 22:27

        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.

        N Offline
        N Offline
        never_ever
        wrote on 12 Nov 2015, 15:43 last edited by never_ever 11 Dec 2015, 18:16
        #3

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

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 12 Nov 2015, 21:20 last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          1/4

          11 Nov 2015, 14:32

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved