Important: Please read the Qt Code of Conduct -

Qt5 OpenGL sanity check

  • just started updating all my OpenGL demos to Qt 5 and want to check a few things I can't find documented.

    In Qt4 the initializeGL function is called once after the ctor, and I usually use this to setup my basic GL state. In the new version we have some code that checks if the state has been created then calls the init function (as in "this": example)

    I'm trying to create a simpler version as an example for my students and it seems that we don't have a valid OpenGL context until the .show() method is called for the window which means I either have to use an if statement in the render function to setup my basic GL state or do something like this

    @ OpenGLWindow window;
    // and set the OpenGL format
    // set the window size
    window.resize(1024, 720);
    // and finally show;
    // the context is only active once we show so now we can setup GL stuff

    The code in the Window ctor is


    m_context = new QOpenGLContext(this);

    I would assume that create would have a valid context and the make current would allow me to do (in immediate mode GL) something like

    @ glClear(GL_COLOR_BUFFER_BIT);
    int w=this->size().width();
    int h=this->size().height();

    However unless I do a show() this is not accepted, also if I do a show() followed by a call to my initialise() function that does the lookAt code I get a brief flash of the old window then the lookat version.

    hope this all makes sense if anyone can tell me the proper way of doing things (I was hoping of avoiding the branch shown in the demo and having the needsInitialize code)


Log in to reply