0

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();

}

9
  • 2
    What makes you conclude that it isn’t blocking it? Commented Feb 16, 2020 at 11:50
  • @Darklighter i am freely able to click on button of the GUI and the buttons perform according to their signal and slots. Commented Feb 16, 2020 at 11:52
  • I should have got some freeze kind of feeling if the buttons where blocked. Commented Feb 16, 2020 at 11:52
  • what does w.render() do? Commented Feb 16, 2020 at 11:54
  • Try adding QPushButton pb("Press"); pb.show(); immediately before while (!glfwWindowShouldClose(window)). Can you interact with the pushbutton? Commented Feb 16, 2020 at 11:55

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

8 Comments

yes that is the problem i am facing initially all openGl rendering was been done in another thread but i realised that gl_deleteBuffers were not able to delete the VAO , VBO.
@Summit wait, is that library Wavefront or some class you called WavefrontRenderer (e.g. because you render OBJs)?
That is a class which i have created.
@Summit perhaps you should abadon GLFW direct use and move that render() call to QOpenGLWidget's paintGL. Otherwise I don't know why you need Qt.
this class is derived from QMainwidow
|
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.