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. QT / OpenGL and Switch to fullscreen crashes
Forum Updated to NodeBB v4.3 + New Features

QT / OpenGL and Switch to fullscreen crashes

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.3k 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.
  • P Offline
    P Offline
    procrash
    wrote on last edited by procrash
    #1

    Hi,

    I'm currently trying to dig in to the details how to use QT in combination with OpenGL
    In the past I've been using glBegin and glEnd commands to draw my content. I read that this is outdated so I tried updating my code to match up with the rendering pipeline in QT.

    I tried to implement a simple example just drawing a red rectangle in an QTOpenGLWidget and provide the possibility to switch to fullscreen by double clicking on the rendering content.

    This worked in the past with glBegin and glEnd and also worked as long as I created the vertices on the fly in the rendering routine but crashes now when I create the content beforehand and just switch to the vertex Array buffer in the paint routine.

    This is my code so far:

    template<class T>
    void View3D<T>::initializeGL()
    {
        glClearColor(0,0,0,255);
    
        glEnable(GL_DEPTH_TEST);
        glShadeModel(GL_SMOOTH);
        glEnable(GL_MULTISAMPLE);
    
        m_program = new QOpenGLShaderProgram(this);
        m_program->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/shaders/vertexShader.glsl");
        m_program->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/shaders/fragmentShader.glsl");
    
        m_program->link();
        m_posAttr = m_program->attributeLocation("posAttr");
    
        GLfloat vertices[] = {
           +0.0f, +1.0f, 0.0f,
           -1.0f, -1.0f,   0.0f,
           +1.0f, -1.0f,   0.0f
        };
    
        m_vbo.create();
        m_vbo.bind();
        m_vbo.setUsagePattern(QOpenGLBuffer::StaticDraw);
        m_vbo.allocate(vertices, sizeof(vertices));
    
        m_vao.create();
        m_vao.bind();
    
        glEnableVertexAttribArray(0);
        m_program->setAttributeBuffer(0,GL_FLOAT, 0, 3, 0);
    
        m_vbo.release();
        m_vao.release();
       m_program->release();
    }
    
    
    template<class T>
    void View3D<T>::paintGL()
    {
    
        this->makeCurrent();
    
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
        m_vao.bind();
        m_program->bind();
    
        glDrawArrays(GL_TRIANGLES, 0, 3);
    
        m_program->release();
        m_vao.release();
    }
    
    
    template<class T>
    void View3D<T>::mouseDoubleClickEvent(QMouseEvent *e) {
        if(isFullScreen())
        {
            setWindowFlags(Qt::Widget);
            showNormal();
    
        } else {
            setWindowFlags(Qt::Window);
            showFullScreen();
        }
    }
    

    Forget about the template class, I need this for other reasons. As soon as I switch to fullscreen the app crashes @ glDrawArrays(GL_TRIANGLES, 0, 3); deep down in OpenGL.

    What could be wrong?

    P 1 Reply Last reply
    0
    • m.sueM Offline
      m.sueM Offline
      m.sue
      wrote on last edited by
      #2

      Hi,
      I do not use makeCurrent in paintGL. I assume it is already done by the Qt framework before it calls paintGL.

      NoneTheless if used you should also call doneCurrent() at the end.
      -Michael.

      1 Reply Last reply
      0
      • P procrash

        Hi,

        I'm currently trying to dig in to the details how to use QT in combination with OpenGL
        In the past I've been using glBegin and glEnd commands to draw my content. I read that this is outdated so I tried updating my code to match up with the rendering pipeline in QT.

        I tried to implement a simple example just drawing a red rectangle in an QTOpenGLWidget and provide the possibility to switch to fullscreen by double clicking on the rendering content.

        This worked in the past with glBegin and glEnd and also worked as long as I created the vertices on the fly in the rendering routine but crashes now when I create the content beforehand and just switch to the vertex Array buffer in the paint routine.

        This is my code so far:

        template<class T>
        void View3D<T>::initializeGL()
        {
            glClearColor(0,0,0,255);
        
            glEnable(GL_DEPTH_TEST);
            glShadeModel(GL_SMOOTH);
            glEnable(GL_MULTISAMPLE);
        
            m_program = new QOpenGLShaderProgram(this);
            m_program->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/shaders/vertexShader.glsl");
            m_program->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/shaders/fragmentShader.glsl");
        
            m_program->link();
            m_posAttr = m_program->attributeLocation("posAttr");
        
            GLfloat vertices[] = {
               +0.0f, +1.0f, 0.0f,
               -1.0f, -1.0f,   0.0f,
               +1.0f, -1.0f,   0.0f
            };
        
            m_vbo.create();
            m_vbo.bind();
            m_vbo.setUsagePattern(QOpenGLBuffer::StaticDraw);
            m_vbo.allocate(vertices, sizeof(vertices));
        
            m_vao.create();
            m_vao.bind();
        
            glEnableVertexAttribArray(0);
            m_program->setAttributeBuffer(0,GL_FLOAT, 0, 3, 0);
        
            m_vbo.release();
            m_vao.release();
           m_program->release();
        }
        
        
        template<class T>
        void View3D<T>::paintGL()
        {
        
            this->makeCurrent();
        
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        
            m_vao.bind();
            m_program->bind();
        
            glDrawArrays(GL_TRIANGLES, 0, 3);
        
            m_program->release();
            m_vao.release();
        }
        
        
        template<class T>
        void View3D<T>::mouseDoubleClickEvent(QMouseEvent *e) {
            if(isFullScreen())
            {
                setWindowFlags(Qt::Widget);
                showNormal();
        
            } else {
                setWindowFlags(Qt::Window);
                showFullScreen();
            }
        }
        

        Forget about the template class, I need this for other reasons. As soon as I switch to fullscreen the app crashes @ glDrawArrays(GL_TRIANGLES, 0, 3); deep down in OpenGL.

        What could be wrong?

        P Offline
        P Offline
        procrash
        wrote on last edited by
        #3

        @procrash said in QT / OpenGL and Switch to fullscreen crashes:

        Hi,

        I'm currently trying to dig in to the details how to use QT in combination with OpenGL
        In the past I've been using glBegin and glEnd commands to draw my content. I read that this is outdated so I tried updating my code to match up with the rendering pipeline in QT.

        I tried to implement a simple example just drawing a red rectangle in an QTOpenGLWidget and provide the possibility to switch to fullscreen by double clicking on the rendering content.

        This worked in the past with glBegin and glEnd and also worked as long as I created the vertices on the fly in the rendering routine but crashes now when I create the content beforehand and just switch to the vertex Array buffer in the paint routine.

        This is my code so far:

        template<class T>
        void View3D<T>::initializeGL()
        {
            glClearColor(0,0,0,255);
        
            glEnable(GL_DEPTH_TEST);
            glShadeModel(GL_SMOOTH);
            glEnable(GL_MULTISAMPLE);
        
            m_program = new QOpenGLShaderProgram(this);
            m_program->addShaderFromSourceFile(QOpenGLShader::Vertex, ":/shaders/vertexShader.glsl");
            m_program->addShaderFromSourceFile(QOpenGLShader::Fragment, ":/shaders/fragmentShader.glsl");
        
            m_program->link();
            m_posAttr = m_program->attributeLocation("posAttr");
        
            GLfloat vertices[] = {
               +0.0f, +1.0f, 0.0f,
               -1.0f, -1.0f,   0.0f,
               +1.0f, -1.0f,   0.0f
            };
        
            m_vbo.create();
            m_vbo.bind();
            m_vbo.setUsagePattern(QOpenGLBuffer::StaticDraw);
            m_vbo.allocate(vertices, sizeof(vertices));
        
            m_vao.create();
            m_vao.bind();
        
            glEnableVertexAttribArray(0);
            m_program->setAttributeBuffer(0,GL_FLOAT, 0, 3, 0);
        
            m_vbo.release();
            m_vao.release();
           m_program->release();
        }
        
        
        template<class T>
        void View3D<T>::paintGL()
        {
        
            this->makeCurrent();
        
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        
            m_vao.bind();
            m_program->bind();
        
            glDrawArrays(GL_TRIANGLES, 0, 3);
        
            m_program->release();
            m_vao.release();
        }
        
        
        template<class T>
        void View3D<T>::mouseDoubleClickEvent(QMouseEvent *e) {
            if(isFullScreen())
            {
                setWindowFlags(Qt::Widget);
                showNormal();
        
            } else {
                setWindowFlags(Qt::Window);
                showFullScreen();
            }
        }
        

        Forget about the template class, I need this for other reasons. As soon as I switch to fullscreen the app crashes @ glDrawArrays(GL_TRIANGLES, 0, 3); deep down in OpenGL.

        What could be wrong?

        Found one strange issue. When I recreate the vbo everything is fine. How can I avoid that QT invalidates the vbo when it is switching to fullscreen? As far as I understood the vertex buffers should not be touched by QT during the switch.

        1 Reply Last reply
        0
        • m.sueM Offline
          m.sueM Offline
          m.sue
          wrote on last edited by
          #4

          Hi,
          I do not to create it every time in paintGL, but only bind (and release) it every time.
          -Michael.

          1 Reply Last reply
          1

          • Login

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