0
votes

I am using GLFW along with QT for an opengl application.

i have a while loop inside the main function.

Why the while loop is not blocking the QT GUI ?

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    cont.SetName("RootItem");
    TreeModel* model = new TreeModel("RootElement", &cont);
    WavefrontRenderer w(model);
    w.show();
    glfwInit();
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
    glfwWindowHint(GLFW_SAMPLES, 4);
    GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "Renderer", nullptr, nullptr);   // 
    glfwMakeContextCurrent(window);
    GLenum GlewInitResult;
    glewExperimental = GL_TRUE;
    GlewInitResult = glewInit();

    w.InitData();

    while (!glfwWindowShouldClose(window))
    {
        glClearColor(0.0, 0.3, 0.3, 0.0);
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
        w.render();     
        glfwPollEvents();
        glfwSwapBuffers(window);
    }
    // glfw: terminate, clearing all previously allocated GLFW resources.
    // ------------------------------------------------------------------
    glfwTerminate();
    //return 0;

    return a.exec();

}

3
What makes you conclude that it isn’t blocking it?Darklighter
@Darklighter i am freely able to click on button of the GUI and the buttons perform according to their signal and slots.Summit
I should have got some freeze kind of feeling if the buttons where blocked.Summit
what does w.render() do?Darklighter
Try adding QPushButton pb("Press"); pb.show(); immediately before while (!glfwWindowShouldClose(window)). Can you interact with the pushbutton?G.M.

3 Answers

1
votes

It seems like glfwPollEvents acts in a similar enough way to QApplication::exec such that (some) events get properly processed.
They probably both call DispatchMessage (see) which then lets registered callback for a window handle the event.
But it might also be that both do additional bookkeeping which could make reliance on that error prone.

1
votes

You're not using QApplication event pump at all, you short-circuited on Moodle\glfw\Wavefront library event loop.

Qt's OpenGl support via QOpenGLWidget directly works with paintGL method which ought to perform all rendering and which is called from inside of event loop. If you're not using that, you'll have somehow combine two threads, which is problematic that both OpenGL pipeline and Qt main loop on some platforms are limited to be usable ONLY in main thread.

0
votes

you are not even starting the Qt application event loop because you are not calling the a.exec() as your code is I side the while loop. I'm no opengl expert but I guess the window you are seeing is the one rendered by opengl itself not a gl canvas inside you qt application window.