OpenGL newbie - why won't these lines display properly?



  • I need to make it so part of my Qml view is "taken over" by some non-Qt OpenGL rendering, and I was having issues getting a texture to display properly so I thought I would just draw a line and get that to work before moving on to more complicated code.

    I took the Squircle sample code ( http://qt-project.org/doc/qt-5/qtquick-scenegraph-openglunderqml-example.html ) and modified it slightly so it would draw in a specified portion of the screen (instead of the entire screen) and that is working perfectly. Then, I modified just the renderer::paint() function to initially draw three green lines, and after 2 seconds to instead draw one blue line:

    @void CtRenderer::paint()
    {
    static int n = 0;

    if (n == 0)
    {
        glViewport(m_rect.x() + 10, m_rect.y() + 10, m_rect.width() - 20, m_rect.height() - 20);
    
        glEnable(GL_SCISSOR_TEST);
        glScissor(m_rect.x() + 10, m_rect.y() + 10, m_rect.width() - 20, m_rect.height() - 20);
    
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_LIGHTING);
    
        // glClearColor(1, 0, 0, 1);
        // glClear(GL_COLOR_BUFFER_BIT);
    
        glLineWidth(10);
        glColor4f(0.0, 1.0, 0.0, 1);
        glBegin(GL_LINES);
        glVertex3f(0.0, 0.0, 1);        glVertex3f(1, 0.5, 1);
        glVertex3f(0.0, 0.0, 1);        glVertex3f(0.5, 0.5, 1);
        glVertex3f(0.0, 0.0, 1);        glVertex3f(0.5, 1, 1);
        glEnd();
    }
    else if (n == 120)
    {
        glViewport(m_rect.x() + 10, m_rect.y() + 10, m_rect.width() - 20, m_rect.height() - 20);
    
        glEnable(GL_SCISSOR_TEST);
        glScissor(m_rect.x() + 10, m_rect.y() + 10, m_rect.width() - 20, m_rect.height() - 20);
    
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_LIGHTING);
    
        // glClearColor(1, 0, 0, 1);
        // glClear(GL_COLOR_BUFFER_BIT);
    
        glLineWidth(10);
        glColor4f(0.0, 0.0, 1.0, 1);
        glBegin(GL_LINES);
        glVertex3f(0.0, 0.0, 1);        glVertex3f(0.4, 0.8, 1);
        glEnd();
    
    }
    n++;
    
    return;
    

    }@

    What I get instead are three gray lines that flicker continuously and never change to being a single line. I'm relatively new to OpenGL, so I'm probably doing something stupid. Can someone point me in the right direction with this code?

    Thanks!
    Chris


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.